Hello, I have just joined codechef and am facing some technical difficulties. I have written a program for the LEADGAME problem but it returns WA or wrong answer. I am pretty sure my algorithm is right. Please help.
My Program
In round 1 player 1 scored: 17 and player 2 scored: 33
The cumulative scores are now - player 1: 17; player 2: 33
New best lead: player 2 has a lead of 16 over player 1
In round 2 player 1 scored: 26 and player 2 scored: 60
The cumulative scores are now - player 1: 43; player 2: 93
New best lead: player 2 has a lead of 50 over player 1
In round 3 player 1 scored: 34 and player 2 scored: 32
The cumulative scores are now - player 1: 77; player 2: 125
In round 4 player 1 scored: 27 and player 2 scored: 22
The cumulative scores are now - player 1: 104; player 2: 147
Final winner/ lead:
2 50
I have tried that too but my program still does not work.
It does output “2 50” but it returns WA when I submit.
My program is: #include <stdio.h> #include <stdlib.h> #include <time.h>
typedef struct inp
{
int teamno;
int score;
}inp;
int main()
{
int rounds;
int curbig1=0;
int curbig2=0;
inp high;
scanf("%d", &rounds);
for(int i=0; i<rounds; i++)
{
int t1;
int t2;
scanf("%d %d", &t1, &t2);
curbig1=curbig1+t1;
curbig2=curbig2+t2;
if((t1>t2)&&(curbig1>curbig2))
{
high.score=curbig1-curbig2;
high.teamno=1;
}
if((t2>t1)&&(curbig2>curbig1))
{
high.score=curbig2-curbig1;
high.teamno=2;
}
}
printf("%d %d", high.teamno, high.score);
}
My output is:
This new solution fails for the following testcase:
3
32 13
31 42
23 42
The answer is
1 19
In round 1 player 1 scored: 32 and player 2 scored: 13
The cumulative scores are now - player 1: 32; player 2: 13
New best lead: player 2 has a lead of 19 over player 1
In round 2 player 1 scored: 31 and player 2 scored: 42
The cumulative scores are now - player 1: 63; player 2: 55
In round 3 player 1 scored: 23 and player 2 scored: 42
The cumulative scores are now - player 1: 86; player 2: 97
Final winner/ lead:
1 19