problem tlg help

4BViVd - Online C++ Compiler & Debugging Tool - Ideone.com what is wrong with this solution of tlg

In the problem statement you are required to calculate the lead of the each player and find the maximum lead of them … LEAD means that the while the game is in progress you keep on getting your score added to the previous scores and if you still win you are in LEAD


You are just taking each of the score of the player and then checking the maximum from that .Hope your understood that, if not don’t hesitate to prompt me.

HAPPY CODING

@rahulsup

Bro you missed & in


scanf("%d%d",&p1,p2);

and on fixing that bug your code gives output
2 2

for input:

5
140 82
89 134
90 110
112 106
88 90

where as actual output should be

Output:
1 58

Considering one more test case

Input:
15
140 82
89 134
90 110
112 106
88 90
129 112
2 69
0 67
220 34
13 579
246 456
121 20
4 950
146 674
941 897

Expected Output:
2 2083 

Your Output:
44 1

Try to fix other bugs…

and if you need help, discussion forum is always there for you… :slight_smile:

Happy Debugging… :slight_smile:

1 Like

Let us suppose we are allowed to have the same scores (i.e Draw) …And suppose the scores are in the order as :

1 2

1 1

4 2

Total1    Total2    Lead    Winner 
  1         2         1       2
  2         3         1       2
  6         5         1       1

Then according your solution the answer will be 2 but the correct answer is 1

The reason for this is the described in the table below:
So the maximum lead is 1 while your program will print 2 as the maximum lead
And apart from the bugs reported by @rishabhprsd7 …There is one more bug in the line when you print your answer you are missing the space between the two outputs

Do prompt if you still have any doubts

HAPPY CODING

I’m sorry for asking this but is the question about comparison between the total score of the players or maximum lead in a round? Because as I read the question, in paragraph 2 it states that “the player with the higher
total score is declared the winner”. Now I’m confused.
Link to my answer: http://www.codechef.com/viewsolution/6562399

Thanks for the help.

sorry nickzuck_007 but i did not understand what you are trying to say i guess i interpreted the question wrongly

sorry nick but i read question again but its not asking to calculate the the sum of all score and then compare

thanks rishabh

most welcome… :slight_smile:

1 Like

#include
#include
using namespace std;
int main()
{
int long t,i,p1,p2,c,position=0,max=0;
int a[10002];
scanf("%d\n",&t);
for(i=0;i<t;i++)
{
scanf("%d%d",&p1,&p2);
if(p1>p2)
{
c=p1-p2;
a[2i]=c;
a[2
i+1]=1;
}
if(p2>p1)
{
c=p2-p1;
a[2i]=c;
a[2
i+1]=2;
}

}
max=a[0];
for(i=0;i<2*t;i++)
{
	if(a[2*i]>a[0])
	{
		max=a[2*i];
		position=2*i+1;
	}
}
printf("%d%d",max,a[position]);

}

can you tell me my mistake

@savitrasapre is your solution showing the correct ans

No. Though when I run it through the sample provided it is giving the desired result. I don’t know why is it saying “Wrong Answer”.

@rahulsup && @savitasapre …If you watch cricket you may notice that in a test match the team with the highest number of total score is declared as the winner after the 2 innings … A team who is not the winner may definitely have the lead in the first game.An almost same question is here but with the condition that the winner is the one who have scored the maximum lead corresponding to a particular innings (round) in a game …@savitasapre you may check my above answers for better understanding

I am not saying you to calculate the sum of all the scores neither …I am asking to calculate the sum till the point the game has already been proceeded and then check for the LEAD ,since when the game is in continuation past records are not lost …once a game has finished all the rounds you must loose all the previous values of the players…You must try by watching a test match or getting some details by your friend about test matches in cricket …If you still have doubts , ask them

#include
using namespace std;

int main() {
long int t;
cin>>t;
long int max=0,p=0;
for(int i=0;i<t;i++)
{int a1,a2;
cin>>a1>>a2;
a1-=a2;
if(max<a1)
{
max=a1;
}
else if(max<(-a1))
{
max=(-a1);
}
if(max==a1)
p=1;
else if(max==(-a1))
p=2;
else
continue;
}
cout<<p<<" "<<max;

return 0;

}
can you help me in debugging it.its giving desired output for test case but giving WA when i submitted it