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;
}
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 .
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 .
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…
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