can i ask whats wrong with my code? i got WA
#include<stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
int a[2][10001];
int main()
{
int t;
scanf("%d",&t);
for(int x=0;x<t;x++)
{
int b,c;
scanf("%d%d",&b,&c);
if(b>c){a[0][x]=1;a[1][x]=b-c;}
else {a[0][x]=2;a[1][x]=c-b;}
}
int W,L(0);
for(int x=0;x<t;x++)if(L<a[1][x]){L=a[1][x];W=a[0][x];}
printf("%d %d\n",W,L);
return 0;
}
here the new code(after modified):
#include<stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
int a[2][10001];
int main()
{
int t,d(0),e(0);
scanf("%d",&t);
for(int x=0;x<t;x++)
{
int b,c;
scanf("%d%d",&b,&c);
if((b+d)>(c+e)){a[0][x]=1;a[1][x]=(d+b)-(c+e);}
else {a[0][x]=2;a[1][x]=(c+e)-(b+d);}
d+=b;e+=c;//printf("%d %d\n",d,e);
}
//for(int x=0;x<t;x++)printf("%d\n",a[1][x]);
int W,L(0);
for(int x=0;x<t;x++)if(L<a[1][x]){L=a[1][x];W=a[0][x];}
printf("%d %d\n",W,L);
scanf("%d",t);
}
hi @aqua_laguna
Coming to the problem with your code, well read the problem statement carefully. You need to add scores of individual players in each round. ie.
Let, s(Pij) denote the score of player i in round j.
then, for any j<=n the score is the sum of all previous rounds plus the current score and then you need to find the lead.
so for player 1 in round 5:
ie s(P15)=s(P11)+s(P12)…+s(P15);
See this image carefully(belongs to the question page itself):
As you can see
what you have done:
You have found the lead using scoresheet ie the first table itself. But thats not the actual score! that’s just the score for that particular round.
what you need to do:
Refer to the second table and see how actual score comes.
for player 1 the score after round 2 is 140+89, you have considered only 89.
for player 2 the score after round 3 is 82+134+110 you have considered only 110
So, basically you just maintain 2 variables say A and B denoting the total score. Instead of comparing (b-c) >L in your code. first do,
A=A+b and B=B+c and then compare A and B;
And, this is a working code(first try on your own again use this just incase you need to refer)
Hope this helps!
1 Like
thx @sunny_patel my code works got ac!!!