the lead game problem....whats wrong with the logic?

#include

using namespace std;

int main(){

int N,t=0,p=0,Si,Ti,l,j,win,max=0;

cin>>N;

for(int i=1;i<=N;i++){
cin>>Si>>Ti;

t+=Si;
p+=Ti;

if(t>p){
    l=Si-Ti;
    j=1;
}
else if(t<p){
        l=Ti-Si;
        j=2;
}
if(max<=l){
        max=l;
        win=j;
}

}

cout<<win<<" "<<max;

return 0;
}

your code snippet should look like this

 if(abs(t-p)>max)
 {
 max=abs(t-p);
if(t>p)
player=1;
else
player=2;
}

 printf("%d %d",player,max);

You should store t-p or p-t instead of si-ti or ti-si. Read the sample test case properly and you will understand why you should do that. :slight_smile:

tried with the abs thing…still getting wrong answer

got it…thanks a lot!! :smiley:

i am not asking you to try abs @sharan669v , i wanted to say smthing else,
look i have stored t-p in max ,what you were doing is storing ti-si

you are welcome