TLG - Editorial

array
easy
editorial

#81

#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*>>p2*;
}
for(int i=0;i<n;i++)
{
temp1=temp1+p1*;
temp2=temp2+p2*;
lead*=temp1-temp2;
}
for(int i=0;i<n;i++)
{
mlead*=abs(lead*);
}
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;

}


#82

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


#83

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)


#84

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)


#85

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


#86

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*>>b*;
c*=a*-b*;
}
x = c[0],m = c[0];
for (i = 1; i < n; i++)
{if (c* > x)
x = c*;
}
{if (c* < x)
m = c*;
}
int j=abs(x);int k=abs(m);
if(j>k)
{cout<<“1”<<" “<<j;}
else
{cout<<“2”<<” "<<k;}

}


#87

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.


#88

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.


#89

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


#90

Search the forums once. Intense profit :3


#91

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


#92

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]);

}

}


#93

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


#94

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