TLG - Editorial

#include
#include
#include

using namespace std;

int main()
{
int n;
cin>>n;
int p1[n],p2[n],lead[n],mlead[n],temp1=0,temp2=0;
for(int i=0;i<n;i++)
{
cin>>p1[i]>>p2[i];
}
for(int i=0;i<n;i++)
{
temp1=temp1+p1[i];
temp2=temp2+p2[i];
lead[i]=temp1-temp2;
}
for(int i=0;i<n;i++)
{
mlead[i]=abs(lead[i]);
}
sort(lead,lead+n);
sort(mlead,mlead+n);
if(lead[n-1]>0)
cout<<1<<" “<<mlead[n-1];
else if(lead[n-1]<0)
cout<<2<<” "<<mlead[n-1];

return 0;

}

import java.util.Scanner;

class LeadGame {

public static void main(String[] args){
    int a,b,t,pA=0,pB=0,currentLeadingPlayer=0,currentlead=0;
    int winningLead=0,winningPlayer=0;

    Scanner scanner = new Scanner(System.in);
    t =scanner.nextInt();
    while (t-->0){
        a=scanner.nextInt();
        b=scanner.nextInt();

        pA +=a;//adding previous score of a
        pB +=b;//adding previous score of b

        // If confused why am i doing this look in comment section

        if (pA>pB){
            currentLeadingPlayer =1;
            currentlead = pA-pB;
        }else {
            currentLeadingPlayer =2;
            currentlead = pB-pA;
        }

        if (winningLead<currentlead){
            winningLead = currentlead;
            winningPlayer = currentLeadingPlayer;
        }
    }
    System.out.println(winningPlayer+" "+winningLead);
}

}

/*
Go Look in problem Statement again the second table shows us that for every player the score is added from previous score
and then the lead is calculated on those updated scores
Based on lead which player is selected
*/

Support with a upvote if it helped

nf = input()
ni = int(nf)
if ni >= 1 and ni <= 10000 :
lead = []
lead1 = []
R = []
even = []
for x in range(1,ni+1):
splitted = input().split()
for y in splitted :
if (0 > int(y) or int(y) > 1000 ):
exit()
else :
R.append(int(y))
n = 0
while n < 2*int(nf):
even.append(n)
n = n + 2
n = ni
for y in even :
if R[y] > R[y+1]:
L = R[y] - R[y+1]
lead.append(L)
lead1.append(1)
else:
L = R[y+1] - R[y]
lead.append(L)
lead1.append(2)
maxi = max(lead)
z = lead.index(maxi)
m = lead1[z]
print(m,maxi)

What is wrong with the following code ?

nf = input()
ni = int(nf)
if ni >= 1 and ni <= 10000 :
lead = []
lead1 = []
R = []
even = []
for x in range(1,ni+1):
splitted = input().split()
for y in splitted :
if (0 > int(y) or int(y) > 1000 ):
exit()
else :
R.append(int(y))
n = 0
while n < 2*int(nf):
even.append(n)
n = n + 2
n = ni
for y in even :
if R[y] > R[y+1]:
L = R[y] - R[y+1]
lead.append(L)
lead1.append(1)
else:
L = R[y+1] - R[y]
lead.append(L)
lead1.append(2)
maxi = max(lead)
z = lead.index(maxi)
m = lead1[z]
print(m,maxi)

rounds = int(input())
pOne = []
pTwo = []

for i in range(0, rounds):
(a, b) = input().split()
lead = int(a) - int(b)
if lead>0 :
pOne.append(lead)
else :
pTwo.append(lead)

mOne = max(pOne)
mTwo = max(pTwo)

if mOne>mTwo :
print("{1} {0}".format(mOne,1), end=’ ‘)
else :
print("{1} {0}".format(mTwo,2), end=’ ')

Can somebody help me with this code. It is giving correct answer with the given values in the question.But after submitting it shows wrong answer. Any help will be appreciated. Thank you

Please reply me that what is wrong in my code. it is poping wrong answer.
Code:
#include <bits/stdc++.h>

using namespace std;

int main()
{ int n,i,a[20000],b[20000],c[20000],x=0,m=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
c[i]=a[i]-b[i];
}
x = c[0],m = c[0];
for (i = 1; i < n; i++)
{if (c[i] > x)
x = c[i];
}
{if (c[i] < x)
m = c[i];
}
int j=abs(x);int k=abs(m);
if(j>k)
{cout<<“1”<<"\t"<<j;}
else
{cout<<“2”<<"\t"<<k;}

}

I checked for sample input given in the problem. Tried couple of examples myself and it works fine. Can you please point out what is wrong here which prevents my answer form getting accepted.

The question is a bit unclear. Actually your solution is calculating lead, in each round. But the correct solution requires you to calculate the cumulative lead after each round.

What is wrong with my code? It is working fine with sample input, but on submitting it codechef says ‘Wrong Answer’.

My answer: link text

Search the forums once. Intense profit :3

What is wrong in this?
It is working fine in eclipse, but codechef editor shows the wrong answer.

Please tell what is wrong with my approach. am getting correct answer in my IDE. and even in codechef it showing run and compilation is success but it is showing output not matching.

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
public class Main
{

static int n;
static Scanner scanner = new Scanner(System.in);
private static long[] a;

private static int X;
private static int X2;

public static void main(String[] args) {
	int n;
	int w = 0;
	Scanner scanner = new Scanner(System.in);
	n = scanner.nextInt();
	a = new long[n];
	for (int i = 0; i < n; i++) {
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		if (A > B) {
			a[i] = A - B;
		} else {
			a[i] = B - A;
		}

		/*
		 * System.out.println("A > X + B: " + A + ",  " + X + ",  " + B); if (A > X + B)
		 * { X = A; w = 1; } else { X = B; w = 2; }
		 * 
		 * System.out.println("A > X + B and W : " + A + ",  " + X + ",  " + B + ",  " +
		 * w);
		 */
		if (A - B > X) {
			X = A - B;
			// w = 1;
		} else {
			X2 = -(A - B);
			// w = 2;
		}

		if (X > X2) {
			w = 1;
		} else {
			w = 2;
		}
	}
	Arrays.sort(a);

	System.out.print(w + " ");
	System.out.println(a[n - 1]);

}

}

Please Help!
I am having write answer for sample test case but every time I submit my solution to the judge I am getting wrong answer.

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

int main()
{
ll n;
cin >> n;
ll s[n],t[n];
vector s1,t1;
for(ll i=0;i<n;i++)
cin >> s[i] >> t[i];
for(ll i=0;i<n;i++)
{
if(s[i]-t[i]>0)
{
s1.push_back(s[i]-t[i]);
}
else
t1.push_back(t[i]-s[i]);
}
ll max1=-1,max2=-1;
if(s1.size()>0)
{
sort(s1.begin(),s1.end(),greater());
max1 = s1[0];
}
if(t1.size()>0){
sort(t1.begin(),t1.end(),greater());
max2 = t1[0];}
if(max1>max2)
cout << “1” << " " << max1;
else
cout << “2” << " " << max2;
return 0;
}

For everybody who is asking the reason for WA, the scores are cumulative, read the question once again. The lead is counted cumulatively not one at a time.
Hope it helps

whats wrong with my code :sweat_smile: when i run it against custom input it give write answer but when i submit it then wrong answer is display please if somebody know problem with my code please tell me . my code is this :point_down::point_down::point_down::point_down::point_down::point_down:
#include <stdio.h>

int main(void) {
// your code goes here

int n;
scanf("%d",&n);
int a[n],b[n],max=0,p=1,d;
for(int i=0; i<n; i++)
{
    scanf("%d%d",&a[i],&b[i]);
    d=a[i]-b[i];
    if(abs(d)>max)
    {
        max = abs(d);
        if(d<0) p=2;
        else p=1;
    }
}
printf("\n%d %d",p,max);
return 0;

}

What is wrong with my code??

#include
using namespace std;
int main()
{
long int player1;
long int player2,range;
int lead=0,p1=0,p2=0,diff,win=0;
cin>>range;
while(range–)
{
cin>>player1;
p1=p1+player1;
cin>>player2;
p2=p2+player2;
diff=p1-p2;
if(diff>lead)
{
lead=diff;
if(lead>0)
win=1;
else
win=2;
}
}
cout<<win<<" "<<lead<<endl;
return 0;
}

//can u tell me what we have to print?? it is not clear in the question whether we have to print the result and lead of the round 1 or every round result or end result??

//#include
using namespace std;

int main()
{
int n,lead;
cin>>n;
int i = 1,a[2],b[2];
a[0] = 0;
b[0] = 0;
while(n–)
{
cin>>a[1];
cin>>b[1];
a[0] = a[0] + a[1];
b[0] = b[0] + b[1];
}
if(a[0] > b[0])
cout<<"1 "<<a[0]-b[0]<<endl;
else
cout<<"2 "<<b[0]-a[0]<<endl;
// your code goes here
return 0;
}

Not necessary to use use array instead could be done with just the use of simple variables.
ie; Scores of player 1 and 2 are ‘a’ and ‘b’ respectively
Just keep count of the lead ( lead+=a-b; ) every time you input the scores.
If lead is positive it means player 1 is leading and if negative then it means player 2 is leading.
Also store the maximum lead in some variable.
code: CodeChef: Practical coding for everyone

hello guys!
my code is given below.what’s wrong with it .it’s correct in all test cases but when i submitted it’s give me wrong answer…

#include <bits/stdc++.h>
using namespace std;
void check(){
int suma=0,sumb=0,point=0,t,a,b;
cin>>t;
for(int i=0;i<t;i++){
cin>>a>>b;
suma+=a;
sumb+=b;
if(point<abs(suma-sumb))
point=suma-sumb;
}
if(point>0)
cout<<"1 "<<abs(point);
else
cout<<"2 "<<abs(point);
}

int main() {
check();
return 0;
}

Consider the testcase:

4
17 33
26 60
34 32
27 22