• + 2 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;
    

    }