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.
#include <stdio.h>
int main(void) {
// your code goes here
int t,num_a,num_b,diff,i=1,winner,player,grtnum;
scanf("%d",&t);
int arr[t];
scanf("%d%d",&num_a,&num_b);
if(num_a>num_b){
diff=num_a-num_b;
player=1;
}
else{
diff=num_b-num_a;
player=2;
}
winner=player;
grtnum=diff;
while(t>i){{
scanf("%d%d",&num_a,&num_b);
if(num_a>num_b){
diff=num_a-num_b;
player=1;
}
else{
diff=num_b-num_a;
player=2;
}
}
if(diff>grtnum){
grtnum=diff;
winner=player;
}
i++;
}
printf("%d %d",winner,grtnum);
return 0;
}
Please help me out i have tried several custom inputs and it is showing answer correctly but when i submit it ,it shows wrong answer. Please review the code and help me out.
my code is absolutely fine for ALL custom inputs but when i submit it is showing wrong answer can someone please help?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int r;
cin>>r;
int p1[r],p2[r],l[r],n,p[r];
for(int j=0;j<r;j++)
{
cin>>p1[j]>>p2[j];