 # Why am i getting WA In The Lead Game (Easy)?

The output is correct on my computer. I tried several times and with different test cases which are correct on my computer. But it is saying Wrong Answer. What is wrong. Please help me…

My code is- Link to the code

Try This One

#include<stdio.h>
#include<stdlib.h>

int main(void) {
int n,i,p1,p2,a1,a2,max,curr,winner,num;
char ch;
scanf("%d\n",&n);
max = 0;
p1 = p2 = a1 = a2 = 0;
for(i=1;i<=n;i++) {
//scanf("%d %d",&a1,&a2);
num = 0;
ch = getchar();
do { num = num10 + ch -‘0’; ch = getchar(); }while(ch!=’ ');
a1 = num;
num = 0;
ch = getchar();
do { num = num
10 + ch -‘0’; ch = getchar(); }while(ch!=’\n’);
a2 = num;
p1 += a1;
p2 += a2;
if(p1>p2) {
curr = p1-p2;
if(curr>max) {
max = curr;
winner = 1;
}
}
else {
curr = p2-p1;
if(curr>max) {
max = curr;
winner = 2;
}
}
}
printf("%d %d",winner,max);
return 0;
}

While you are calculating the lead you should add the scores of person1 and person2 cumulatively. See the given example in the question.

``````Round     Player 1       Player 2

1             140                 82
2              89                 134
3              90                 110
4             112                 106
5              88                  90
``````

The total scores of both players, the leader and the lead after
each round for this game is given below:

``````Round      Player 1       Player 2     Leader     Lead

1               140           	 82       Player 1     58
2               229           	216       Player 1     13
3               319           	326       Player 2      7
4               431           	432       Player 2      1
5               519           	522       Player 2      3
``````

Here, the lead should be calculated at the end of each round not with the scores of the present round but, with the total score upto that round.
So, while calculating the lead in the second round for player1 the score becomes 140+89 = 229 and similarly, for player2 it is 82+134 = 216. Therefore, the lead is 229 - 216 = 13.