WA for my program (TLG)

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


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

typedef struct inp
{
bool team;
int lead;
}inp;

int main()
{
int rounds;
inp curbig;
curbig.lead=0;
scanf("%d", &rounds);
for(int i=0; i<rounds; i++)
{
int t1;
int t2;
scanf("%d %d", &t1, &t2);
if(t1>t2)
{
if(t1-t2>curbig.lead)
{
curbig.lead=t1-t2;
curbig.team=true;
}
}
else
{
if(t2-t1>curbig.lead)
{
curbig.lead=t2-t1;
curbig.team=false;
}
}
}
printf("%d %d", curbig.team == true ? 1: 2 , curbig.lead);
}


1 Like

I have tried that case and I got this result


I think it has given the correct output. Please let me know what else can be wrong.

The answer should be

2 50
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

5 Likes

Oh. I had read the question wrong. Thank you so much.

1 Like

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
3 Likes

Thank you so much!!! I finally got AC!!!

1 Like

I had changed the program

Can you please walk me through this the same way, my code gives all the correct answers you used in examples here so far, but still WA

#include
using namespace std;
int main()
{
int i, pone, ptwo, leadone = 0, leadtwo = 0;
cin >> i;
for(int a=0; a<i; a++){
cin >> pone >> ptwo;
if(pone>ptwo && (pone-ptwo)>leadone && (pone-ptwo)>leadtwo) leadone += (pone-ptwo);
if(ptwo>pone && (ptwo-pone)>leadone && (ptwo-pone)>leadtwo) leadtwo += (ptwo-pone);
}
if(leadone>leadtwo) cout << "1 " << leadone;
else cout << "2 " << leadtwo;
return 0;
}

good explanation bro , now I understood the problem where I made mistake

1 Like