What is wrong in my solution of Question : The Lead Game

Question Link - https://www.codechef.com/problems/TLG
Question Code - TLG

My Solution is giving correct for sample case but after submitting it is giving wrong answer

#include <bits/stdc++.h>

using namespace std;

int main(){
int n;
cin>>n;
int amx=0;
int bmx=0;
int adif=0;
int bdif=0;
for(int i=1;i<=n;++i){
int a=0,b=0;
cin>>a>>b;
if(a>b){
adif = abs(a-b);
if(adif>amx){
amx= adif;
}
}
else if(a<b){
bdif =abs (b-a);
if(bdif>bmx){
bmx=bdif;
}
}
}
if(adif>bdif){
cout<<“1”<<" “<<amx<<endl;
}
else if(adif<bdif){
cout<<“2”<<” "<<bmx<<endl;
}
return 0;
}

@xurde23
In the last comparisons you are comparing the last lead of the players, not the maximum lead. Try replacing adif/bdif with amx/bmx: if(amx>bmx)

1 Like