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.

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;

Maximum array size has to be 10^7 which is not possible in case of C. I tried Dynamic memory allocation (malloc) which worked but got TLE for bigger test cases

## Array Manipulation

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

I would not suggest eclipsing

`list`

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

## include

## include

## include

## include

int main() {

}

Maximum array size has to be 10^7 which is not possible in case of C. I tried Dynamic memory allocation (malloc) which worked but got TLE for bigger test cases

yeah it is getting a tle. We need to use a different algorithm. I wanted to know what the problem in my code was so i posted my solution.

use long instead of int.