#include
using namespace std;
long int a[100000][2];
int main()
{
int x;
cin>>x;
int large=0,index=0;
for(int i=1;i<=x;++i)
{
for(int j=1;j<=2;++j)
{
cin>>a[i][j];
}
if(a[i][1]<a[i][2])
{
a[i][2]=a[i][2]-a[i][1];
a[i][1]=2;
}
else
{
a[i][2]=a[i][1]-a[i][2];
a[i][1]=1;
}
}
large=a[1][2];
index=a[1][1];
for(int i=1,j=2;i<x;++i)
{
if(large<a[i][2])
{
large=a[i][2];
index=a[i][1];
}
}
cout<<index<<" "<<large<<endl;
return 0;
}
In the last for
loop, i
should run from 1
to x
(both including). i.e., for(int i=1,j=2;i<=x;++i)
1 Like
Here is a sample input where your pgm fails.
5
140 82
89 134
90 110
112 106
88 590
The correct answer is “2 503
”, but your pgm gives “1 58
”
1 Like
My pleasure! You are welcome! 
brother…i am sorry to say that…its still not working…i corrected the mistake u pointed…how many space shud be ther in the output??
Oops! Your logic is wrong.
You are finding the difference of scores of each round. That is indeed a wrong answer.
The question is to find the lead after each round, considering the “total score upto and including that round”, not just the scores of that particular round.
You need to sum up all the values till the current round, and find the difference between them.
The final answer will be the maximum of the difference.
Unfortunately, in the given sample example, the given answer and the answer you get are the same. That is why, the trouble was caused.
Please try and submit after correcting the logic.
1 Like
And also, the number of spaces doesn’t matter. The answer is what matters.
The online judge ignores whitespaces. So, you only need to worry about finding the right answer.
However, it is better, if you stick with just a single space. There is no specific reason for this, but still, this seems to be accepted as a universal practice!! 
1 Like
got correct…really thanks
1 Like