Https://www.codechef.com/viewsolution/26590349 (TLG)

https://www.codechef.com/viewsolution/26590349
anyone please explain whats wrong with my code as codechef is giving compilation error but working fine on codeblocks.

#include
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
int a,b,s1=0,s2=0,t[2000];
long int n,i;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a>>b;
s1=s1+a;
s2=s2+b;
t[i]=s1-s2;
}
sort(t,t+n);

if(abs(t[0])>t[n-1])
    cout<<"2 "<<t[0];
else
    cout<<"1 "<<abs(t[n-1]);
return 0;

}

It seems to compile fine here - are you sure you don’t mean it gives WA or somesuch?

Anyway, on my machine it gives the wrong answer for the testcase:

4
17 33
26 60
34 32
27 22

Edit:

According to the Problem description, what are the bounds of N? What values of N can your program cope with?

@mohitz_007 you got runtime error not compile error
N<=10000 and you gave array size 2000 only

ok , thank you @lx_lovin @ssjgz for suggestions. now it gave AC.

2 Likes