We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Data Structures
  3. Arrays
  4. Array Manipulation
  5. Discussions

Array Manipulation

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • ShubhamV06 4 years ago+ 0 comments

    Can some one please help as to why my solution gives a segmentation fault?

    include

    include

    include

    include

    int main() {

    unsigned long long int n,m,l,b,k,i,val=0;
    scanf("%llu%llu",&n,&m);
    unsigned long long int a[n+1];
    for(i=1;i<=n;i++)
    {
       a[i]=0;    
    }
    while(m--)
    {
        scanf("%llu%llu%llu",&l,&b,&k);        
        for(i=l;i<=b;i++)
        {
           a[i]+=k;    
           if(a[i]>val)
           {
               val=a[i];
           }
        }
    }
    printf("%llu",val);
    return 0;
    

    }

    1|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature