whats wrong with my code when i run it against custom input it give write answer but when i submit it then wrong answer is display please if somebody know problem with my code please tell me . my code is this #include <stdio.h>
int main(void) {
// your code goes here
int n;
scanf("%d",&n);
int a[n],b[n],max=0,p=1,d;
for(int i=0; i<n; i++)
{
scanf("%d%d",&a[i],&b[i]);
d=a[i]-b[i];
if(abs(d)>max)
{
max = abs(d);
if(d<0) p=2;
else p=1;
}
}
printf("\n%d %d",p,max);
return 0;
//can u tell me what we have to print?? it is not clear in the question whether we have to print the result and lead of the round 1 or every round result or end result??
Not necessary to use use array instead could be done with just the use of simple variables.
ie; Scores of player 1 and 2 are ‘a’ and ‘b’ respectively
Just keep count of the lead ( lead+=a-b; ) every time you input the scores.
If lead is positive it means player 1 is leading and if negative then it means player 2 is leading.
Also store the maximum lead in some variable.
code: CodeChef: Practical coding for everyone
can someone review my code ?
Again there are tons of ways to do it but why not this?
works perfectly everywhere, even in custom inputs, fails during submission :
tc = int(input())
list_1 = []
list_2 = []
for i in range(tc):
(a,b) = map(int,input().split(’ '))
list_1.append(a)
list_2.append(b)
max_diff = 0
for j in range(tc):
if list_1[j]>list_2[j] and max_diff < list_1[j]-list_2[j] :
winner = 1
max_diff = list_1[j]-list_2[j]
elif list_1[j]<list_2[j] and max_diff < list_2[j]-list_1[j]:
winner = 2
max_diff = list_2[j]-list_1[j]
i used this code to solve the “The Lead Game” TLG problem. I am getting right output for given test case but upon submitting it shows wrong answer. what could have been gone wrong? please help.