# WA IN THE The Lead Game

I AM GETTING A WA
HERE IS MY CODE PLEASE POINT OUT THE MISTAKES AND EXPLAIN YOUR SOLUTION

#include<bits/stdc++.h>
using namespace std;
#define ll int

int main()
{
ll n;
cin>>n;
ll s[n],t[n],a[n];
ll i;
for(i=0;i<n;i++){
cin>>s[i];
cin>>t[i];

``````}
ll w=0;
for(i=0;i<n;i++){

a[i]=s[i]-t[i];
}

ll k=*max_element(a,a+n);
ll j;
for(i=0;i<n;i++){

if(k==a[i])
j=i;
}

if(s[j]>t[j]){
cout<<1<<" ";
cout<<a[j]<<endl;
}
else{
cout<<2<<" ";
cout<<a[j]<<endl;

}
``````

return 0;
}

In the arrays s[n] and t[n] you are storing the score of player 1 and 2 in each game separately and storing the lead in that particular game itself but according to question what you need to do is that you have to calculate the cumulative score which means score of this game added with the scores of all the previous games and then calculate lead and when this lead is maximum of all you have to declare the winner.
what you can do is store the sum of the score of the previous games in two integers p1 and p2 and then compute the lead at the end of each game in an array.
Hope you got it!!

but can your logic satisfy this case
5
140 82
229 216
319 326
431 432
519 522

Note that the above table contains the cumulative scores.

The winner of this game is Player 1 as he had the maximum lead (58 at the end of round 1) during the game.

(the above two lines are taken from the question itself)

Yes, as in the array a[n](containing the difference of cumulative scores) the lead in the first round is 58 which is maximum of all the the elements(i.e all the differences in cumulative scores) and score of player 1 is high hence player 1 is the winner.

but for the below case

5
140 82
229 216
319 326
431 432
519 522

answer i am getting is 1 71 i.e according to the second round
here is the code
for that

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
ll n;
cin>>n;
ll p1[n],p2[n],a[n];
ll i;
for(i=0;i<n;i++)
{
cin>>p1[i];
cin>>p2[i];

``````}

ll z=0,x=0,g;
for(i=0;i<n;i++)
{
x=x+p1[i];
z=z+p2[i];
g=x-z;
a[i]=abs(g);

}

//for(i=0;i<n;i++)     // this loop is only for seeing the output of a[]
//{
//	cout<<a[i]<<endl;

//}

ll j;
ll k=*max_element(a,a+n);
for(i=0;i<n;i++)
{
if(k==a[i])
{

j=i;

}

}

if(p1[j]>p2[j])
{

cout<<1<<" "<<k<<endl;

}

else
{

cout<<2<<" "<<k<<endl;
}

return 0;
``````

}

You entered wrong input
see here correct input