the lead game: wrong answer

THE LEAD GAME CODE-

I have added all the cumulative scores as well.

#include<iostream>
using namespace std;
int main()
{int n,i,si,ti,w,l=0,temp=0,store[1000],s;
 cin>>n;
for(i=0;i<n;i++)
{cin>>si>>ti;
 store[i]=si-ti;
 if(si-ti>temp||ti-si>temp)
 {s=i;
 	if(si>ti)
  {temp=si-ti;
  w=1;
  }
  else
  { temp=ti-si;
  w=2;}
  }
 }
 for(int j=0;j<=s;j++)
 l=l+store[j];
 if(w==2)
 l=l*(-1);
cout<<w<<" "<<l;
return 0;
}

Search the forums, the mistake in your code has been pointed out multiple times before.

what is the mistake …it is showing right answer in code blocks

Search the forums. :slight_smile:

hehe you have written this only in all other forums

Because I answered this exact question like 3-5 times already xD

NOW WHAT IS THE ERROR??
#include
using namespace std;
int main()
{int n,i,si,ti,w,l=0,temp=0,store[1000],s;
cin>>n;
for(i=0;i<n;i++)
{cin>>si>>ti;
store[i]=si-ti;
if(si-ti>temp||ti-si>temp)
{s=i;
if(si>ti)
{temp=si-ti;
w=1;
}
else
{ temp=ti-si;
w=2;}
}
}
for(int j=0;j<=s;j++)
l=l+store[j];
if(w==2)
l=l*(-1);
cout<<w<<" "<<l;
return 0;
}

now i have added all the commulative leads

IDK what have you done. You were supposed to calculate cumulative score of each round and keep a track of which player is leading by what amount. The one leading with maximum amount in any round wins overall.

we have to calculate the overall lead of the winner or the commulative lead till the maximum amount of lead?

At every round, find cumulative lead. Winner is the one with maximum cumulative lead in any round. Check the example in problem statement, player 1 wins because he got maximum lead of 58 in round 1.