Run time error and Auto input also giving error

As i was solving my first question on codechef, and i am also new in codding i get stuck in this, getting run time error and auto input also giving error . But when i giving the same, custom input its going correct . Please help me on this code

#include <stdio.h>
#define MAX 5000

int main(void)
{
int Si[MAX],Ti[MAX],l,i,n,W;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&Si[i],&Ti[i]);
}
int c1=0,c2=0,max=0;
for(i=0;i<n;i++)
{
c1=c1+Si[i];
c2=c2+Ti[i];
if(c1>c2)
{
l= c1-c2;
if(l>max)
{
max=l;
W=1;
}
}
else
{
if(c2>c1)
{
l=c2-c1;
if(l>max)
{
max=l;
W=2;
}
}
}
}
printf("%d %d",W,max);
return 0;