 # Level Easy -The lead game

hi,
below mentioned source code ran successfuly on my compiler but it is showing wrong answer on code chef. please clarify asap. thanks in advance.

``````#include<stdio.h>
int main()
{
int n,x,y,i,max,winner,winner1,max1=0;
scanf("%d\n",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d/n",&x,&y);
if(x-y>y-x)
{
max=x-y;
winner=1;
}
else
{
max=y-x;
winner=2;
}
if(max>max1)
{
max1=max;
winner1=winner;
}
}
printf("%d %d",winner1,max1);
return 0;
}``````

This question is slightly confusing. the lead at each round is calculated by considering not just the current difference but the difference between the total points scored by the players upto that point. eg.
Consider 2 rounds: 1) 20 30 2) 40 25. In first round 30>20 so 2 is winner and maxdiff is 10. in next round scores to be considered are 20+40 =60 and 30+25=55. diff is 60-55=5 so winner is still 2 and not 1 as you will get.Extend this logic to work for multiple rounds.You can go through my solution if it is still not clear.

1 Like