Beginner problem t

this code of mine is executing well in codechef compliler but on submitting it is showing wrong answer. can sombody tell why ?

#include <stdio.h>
int main() {
int t,n,m,max=0,s=0,r=0,p,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d %d",&n,&m);
s=s+n;
r=r+m;
if(s>r && max<s-r)
{
max=s-r;
p=1;
}
else
{
max=r-s;
p=2;
}
}
printf("%d %d",p,max);
return 0;
}

May be it is not giving any error in codechef compiler because your program has no syntax error.
However your program was giving some answer but your answer was not same as required.

The LOGIC is wrong. Also, format your code before posting or share a link