# TLG Problem: I am using an approach without the use of arrays as mentioned.

HI All, I was solving this problem TLG. The method mentioned in the editorials involves creating 3-4 arrays and then calculating the answer. I am trying a different approach where the lead is calculated during the input of the scores and then compared with the previous lead. I am getting the desired output in my IDE however there seems to be some test case that I am missing because of which I am getting wrong answer at the codechef compiler. Please help in pointing out the mistake in my approach. Here is my code:

``````#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n;
cin>>n;

int a[n];
int b[n];
int p1,p2;
int diff,ans,player;
ans = 0;

p1 = p2 = 0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
cin>>b[i];
p1 += a[i];
p2 += b[i];
diff = abs(a[i] - b[i]);
if(diff > ans)
{
ans  = diff;
player = (p1 > p2)?1:2;
}
//cout<<p1<<" "<<p2<<endl;
}

cout<<player<<" "<<ans<<endl;

return 0;
}
``````

(i%2) ? 1 : 2;

Why are you doing this . You should compare the two values to know the answer not calculating the odd-even index . Here the values aren’t the current score , but the cumulative score so you need to store the current value of scores and you need to find the maximum difference between them .

1 Like
`````` player = (i%2)?1:2;
``````

This is wrong. Say this testcase-

``````Input
2
140 130
300 140
2 160
Correct Output
1 170
``````

2 Likes

it says cumulative lead , means it gets a lead of 58 , then on the next chance the lead if he gets is added or reduced , get the lead at every stage and add or reduce , when the personal lead will remain the max , that player wins .
it has 58, so at thenext round 2nd player won by 45 points , so player 1 lead reduces by 45, thereby making it 13 and again then reduced by 20 , so in this way u get when a player has a max lead .

1 Like

thanks for your time mate, I was doing this to check which player had the maximum lead… I think I should change this…

I have updated the answer now

I think keeping a track of total scores is enough. Check abs difference, and assign winner to whosoever’s total score is higher at that time.

I didn’t downvote anybody

Yes vijju , there is no need for third array but the editorialist thinks otherwise

I dont have any problem taking it back if its stinging you that much, but correct your answer.

I don’t get it… According to 2nd table, the scores are cumulative whereas the lead isn’t. 58 is the initial lead by player 1 and it stays 58 till the end. Please correct me if I am wrong…

So, That means the player 1 won because he had the lead of 71(58+13)?

updated the comment read it now.

no, it had a lead of 57, but it is reduced by 45 making it a net of 13 lead points for player 1 , and then at the thrd steps player 2 gets a lead of 20 points , so 20-13 makes it a net lead of 7 points for player2

thanks…

The highest lead on cumulative scores is taken.