1

Why am I getting run-time error when running this code? Here's a Test Input Case:

5 3
1 2 100
2 5 100
3 4 100
#include <stdio.h>
long long int s[999999];
// Complete the arrayManipulation function below.
int main()
{
    int n,m,i;
    long int a,b,val,cval;
    scanf("%d %d",&n,&m);
    for(;m>0;m--)
    {
        scanf("%ld %ld %ld",&a,&b,&val);
        s[a-1]+=val;
        if(b!=n)
            s[b]-=val;
    }
    val=s[0];
    cval=s[0];
    for(i=1;i<n;i++)
    {
        cval+=s[i];
        if(val<cval)
            val=cval;
    }
    printf("%ld",val);
    return val;
}

Expected and actual results match but compiler giving run-time error.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

2

The return statement of your application should usually return EXIT_SUCCESS (0) or EXIT_FAILURE (1).

You return a very positive value - which is means for the shell that this was an error. Just change the return value to "0" or EXIT_SUCCESS to remove that "run time error".

See also: What should main() return in C and C++?

elcuco
  • 8,948
  • 9
  • 47
  • 69