The Lead Game - Wrong Answer why?

#include<stdio.h>
int main(){
int t,winner,score=0,s,p1,p2;
scanf("%d",&t);
while(t > 0 && t<= 10000){
scanf("%d %d",&p1,&p2);
if(p1 > 1000 && p1 <= 1 && p2 > 1000 && p2 <= 1)
return 0;
if(p1>p2){
s=p1-p2;
if(s>score){
score=s;
winner=1;
}
}else{
s=p2-p1;
if(s>score){
score=s;
winner=2;
}
}
t–;
}
printf("%d %d\n",winner,score);
return 0;
}

U got it just a bit wrong, the problem statement! What you are doing is just taking scores of one round, subtracting it and then seeing whose lead is maximum. But actually while taking the score of present round, and calculating the lead, you have to also add the scores of the previous rounds to both the players’ scores. My point is :- Say if you are calculating lead for round 4, you have to add the scores of Rounds 1, 2 and 3 in the players’s Round 4 score, then take the lead and then find maximum. It can be clearly visualized from the example given in the problem.

Brother, let me try to explain it to you.

You are calculating the difference between scores obtained in one particular round at a time.

You are supposed to calculate the difference in the cumulative scores at the end of each round, as explained in the example:

Consider the following score sheet for

a game with 5 rounds:

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

The winner of this game is Player 1 as he had the maximum lead (58 at the end of round 1) during the game.

5 Likes