Why I am getting a wrong answer for The Lead Game

I am new to code chef and trying The Lead Game .I can’t figure out why my code is getting a wrong answer as it gives exactly same input output on my local machine.This is what I have written-

#include <stdio.h>
int main()
{
	int N;
	scanf("%d", &N);
	int i;
	int lma=0;
	int lmb=0;
	int p1;
	int p2;
	for (i = 1; i <= N; i++)
	{
		scanf("%d %d", &p1, &p2);
		if (p1 > p2)
		{
			int t = (p1 - p2);
			if (t > lma)
				lma = t;
			

		}
		else
		{
			int t = (p2 - p1);
			if (t > lmb)
				lmb = t;
		}					
	}
	if (lma > lmb)
		printf("%d %d\n",1,lma);
	else
		printf("2 %d\n",2,lmb);
	return 0;
}

Hey @swat009

Your code give wrong output for this test case

15
140 82
89 134
90 110
112 106
88 90
129 112
2 69
0 67
220 34
13 579
246 456
121 20
4 950
146 674
941 897

Correct Output: 2 2083

Your Code’s output: 2 2

Hello, i have understood rishabhprsd7’s idea for the solution ,i applied it but it still gives me a wrong answer.
http://www.codechef.com/viewsolution/6362454

i’ve tried all the possible combinations that i found and all that i could think of, for this problem, and i still received a wrong answer. i don’t know what solutions to try anymore.

Thank you, Bogdan

Hello bogdan ,

I don’t know why are you making this simple problem more and more complicated . first of all remove short int and use int instead (overflow issues).

Look at my code given below for this problem .

import java.util.* ;
class Main{
	public static void main(String []args){
		Scanner sc = new Scanner(System.in) ;
		int W,L,P1,P2,N,S1,S2;
		S1 = S2 = L = W = 0 ; 	
		N = sc.nextInt() ;
		while(N-- > 0){
			P1 = sc.nextInt() ;
			P2 = sc.nextInt() ;
			S1 += P1 ;
			S2 += P2 ;
			if(S1 > S2){
				if(S1-S2 >= L){
					L = S1 - S2 ;
					W = 1 ; 
				}			
			}else{
				if(S2-S1 >= L){
					L = S2 - S1 ; 
					W = 2 ;
				}
			}
		}
		System.out.print(W+" "+L) ;
	}
}

Hope this will help you my friend.

thank you. i just modified from short to int and than it worked.