https://www.codechef.com/problems/TLG getting wrong answer for this problem

#include
#include
using namespace std;

int main()
{
  int n,a,b,d,l,W;
  d=0,l=0;
  cin>>n;
  while((n--)>0)
  {
   a=0;
   b=0;
   cin>>a>>b;
   d=a-b;
   if(abs(d)>l)
   {
    l=abs(d);
    if(d>0)
    W=1;
    else
    W=2;
   }
  }
  cout<<W<<" "<<l;
return 0;
}

my code works properly and displays answer but codechef is sayin wrong answer can someone pls tell what is wrong

While posting ANY question, please select your entire code and then click on the button having 101010 label on it. It makes the code very clear to read.

2 Likes

done sir pls review it and tell my mistake

You are calculating the leader and the lead of individual rounds.
But you have to calculate the leader and the lead at the end of each round. It means, if at the end of 1st round, the 1st player leads by score 5 and in the second round, the second player gets the score 2 more than the first player, then at the end of second round, 1st player leads by score 3.

Got it thanks

1 Like