TLG - Editorial

#include
using namespace std;
int main()

{
int N,Si=0,Ti=0,i,diff1=0,diff2=0;
cin>>N;
for(i=0;i<N;i++)
{
cin>>Si>>Ti;
if(Si>Ti){
if(Si-Ti>diff1)
diff1=Si-Ti;
}
else if(Si<Ti){
if(Ti-Si>diff2)
diff2=Ti-Si;
}
}
if(diff1>diff2)
cout<<1<<" “<<diff1;
else
cout<<2<<” "<<diff2;
return 0;
}
WHAT IS WRONG?? it shows an error when I try submit my code.

Hello , I am using python. Everything in the code seems fine to me but its showing wrong answer. Can anyone help ??

t= input()

list1=[]

list2=[]

difference=[]

for i in range(int(t)):

user=input()

si,ti=user.split()

list1.append(int(si))

list2.append(int(ti))

difference.append(int(si)-int(ti))

sum1=sum(list1)

sum2=sum(list2)

if(max(difference)>abs(min(difference))):

print(1,max(difference))

elif(max(difference)<abs(min(difference))):

print(2,abs(min(difference)))

Your question is not complete may be because of your example case .

import java.util.Scanner;
class Pool
{
public static void main(String []args)
{
int n,first,second,w=0,l=0,test1=0,test2=0,lead1=0,lead2=0;
Scanner s=new Scanner(System.in);
n=s.nextInt();
for(;n>0;n–)
{
first=s.nextInt();
second=s.nextInt();
if(first>second)
{
test1=first-second;
lead1=test1;
if(lead1>lead2)
{l=lead1;
w=1;
}
}
if(second>first)
{
test2=second-first;
lead2=test2;
if(lead2>lead1)
{l=lead2;
w=2;
}
}

}

System.out.println(w+" "+l);

}
}

/////////// what is the problem … output is giving accurate but when submitting, it gives wrong answer

what’s wrong with my code!!!
#include
#include
using namespace std;
int main()
{
int t;
cin>>t;
int l=0;
do
{
int a,b;
cin>>a>>b;
if(abs(a-b)>abs(l))
l=a-b;
t–;
}while(t>0);
if(l>0)
cout<<1<<" “<<abs(l);
else
cout<<2<<” "<<abs(l);
return 0;
}

In this problem lead is considered as cumilative lead and not on basis of individual round.If ur code goes for individual round u will get wrong answer

AC Solution : CodeChef: Practical coding for everyone

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {

/**
 * @param args
 * @throws IOException 
 */

public static void main(String[] args) throws IOException {
	
	BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
	
	int test=Integer.parseInt(bufferedReader.readLine());
	int arr1[]=new int[test];
	int arr2[]=new int[test];
	int score=0;
	int player=0;
	while(test>0){
		String s[]=bufferedReader.readLine().split(" ");
		int ar1C=Integer.parseInt(s[0]);
		int ar2C=Integer.parseInt(s[1]);
		arr1[test-1]=ar1C;
		arr2[test-1]=ar2C;
		test--;
	}
	for(int i=0;i<arr1.length;i++){
		if((arr1[i]-arr2[i])>0 &&(arr1[i]-arr2[i]>score)){
			score=arr1[i]-arr2[i];
			player=1;
		}
		else if((arr1[i]-arr2[i]<0 && Math.abs(arr1[i]-arr2[i])>score)){
			score=arr2[i]-arr1[i];
			player=2;
		}
	}
	System.out.print(player);
	System.out.print(" ");
	System.out.print(score);
	
}

}

my code is working exactly fine with test cases and all other possible inputs but as soon as i hit the submit button it shows wrong answer.
here is the source code.

include

int main ()
{
int n,i,diff,win;
scanf("%d",&n);
int max[n],winer[n],s[n],t[n];
for(i=0;i<n;i++)
{
scanf("%d%d",&s[i],&t[i]);
if(s[i]-t[i]>0)
{
max[i]=s[i]-t[i];
winer[i]=1;

    }
    else if(t[i]-s[i]>0)
        {
            max[i]=t[i]-s[i];
            winer[i]=2;



        }
}
        diff=max[0];
        win=winer[0];
        for(i=0;i<n;i++)
        {
            if(max[i]>=diff)
            {
                diff=max[i];
                win=winer[i];
            }

        }
        printf("%d %d",win,diff);

       return 0;
}

please tell where i m going wrong !

import java.util.;
import java.io.
;
import java.lang.;
import java.math.
;
class Leadgame{

private static void bubbleSort(int[] intArray) {
int z = intArray.length;
            int temp = 0;
           
            for(int i=0; i < z; i++){
                    for(int j=1; j < (z-i); j++){
                           
                            if(intArray[j-1] < intArray[j]){
                                    //swap the elements!
                                    temp = intArray[j-1];
                                    intArray[j-1] = intArray[j];
                                    intArray[j] = temp;
                            }
                           
                    }
            }

}

public static void main(String args[]) throws Exception{
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int m[]=new int[n];
	int k[]=new int[n];
	int a[]=new int[n];
	int b[]=new int[n];
	int t=0,l=0;
	for(int i=0;i<n;i++){
		if(n<=10000){
		m[i]=s.nextInt();
		k[i]=s.nextInt();
		if(m[i]>=1&&m[i]<=1000&&k[i]>=1&&k[i]<=1000){
		if(m[i]>k[i])   //for player 1
		{a[t]=m[i]-k[i];
			t++;}
		else
			{b[l]=k[i]-m[i];  //for player 2
		l++;}}
		else System.exit(0);}
		else System.exit(0);
	}
	//sorting a[t] and b[l] arrays
	
	bubbleSort(a);
	bubbleSort(b);
	
	if(a[0]>b[0])
		System.out.println("1 "+a[0]);
	else if(b[0]>a[0])
		System.out.println("2 "+b[0]);
	else System.exit(0);
	}
	}

// what is the problem with this code
//it isrunning well but not get accepted

rounds=input()
p1_score=[]
p2_score=[]
difference_array=[]
for i in xrange(0,rounds):
a, b = map(int, raw_input().split())
p1_score.append(a)
p2_score.append(b)
for t in range(0,rounds):
difference=p1_score[t]-p2_score[t]
difference_array.append(difference)
difference_array.sort()
x1=abs(difference_array[0])
x2=abs(difference_array[rounds-1])
if x1>x2:
print “2”, x1
elif x2>x1:
print “1”, x2
else:
pass

This is the code I wrote in Python 2.7. Please tell me what’s wrong with this. Test case works fine with it.

what’s wrong with this code
link to code thanks

#include
#include
using namespace std;

int main()
{
int N;
cin >> N;

int B[N];
int A[N];

int lead[N];

int W=0;
long long maxi =0;

for(int i=0; i<N; i++)
{
    cin >> A[i];
    cin >> B [i];
}

for( int i =0; i<N; i++)
{
if(A[i] - B[i] >0 && (A[i] - B[i]) > maxi){
maxi =(A[i] - B[i]);
W =1;
}
else if(B[i] - A[i] > maxi)
{
maxi =(B[i] - A[i]);
W =2;
}
}

cout << W << " " << maxi;
}

Can anyone please help me, whats wrong in my code. It works fine in my pc but when i submit it shows wrong answer.

What’s wrong with my code please

import sys
count = int(input())
p1_leads = []
p2_leads = []

while count != 0:
    x, y = [int(item) for item in input().split()]
    if (x != y):
        if (x > y):
            p1_leads.append(x-y)
        else:
            p2_leads.append(y-x)
    else:
        sys.exit(1)
    count -=1

if max(p1_leads) > max(p2_leads):
    print(1, max(p1_leads))
else:
    print(2, max(p2_leads))

where is the problem in following code. it gives right answer in my pc but wrong answer shows in codechef compiler. please help!

#include<iostream>
using namespace std;
main()
 {
   int n;
   cin>>n;
   int p1[n],p2[n],p1lead[n],p2lead[n],j=0,k=0;
   for(int i=0;i<n;i++)
        {
	  cin>>p1[i]>>p2[i];
	  if(p1[i]>p2[i])
	 {
		p1lead[j]=p1[i]-p2[i];
		++j;;
	}
	else
	{
		p2lead[k]=p2[i]-p1[i];
		++k;
	}
	
}
int max1,max2;
max1=p1lead[j-1];
for(int p=j-2;p>=0;p--)
{
	if(p1lead[p]>max1)
	{
		max1=p1lead[p];
		}	
}
max2=p2lead[k-1];
for(int q=k-2;q>=0;q--)
{
	if(p1lead[q]>max1)
	{
		max2=p1lead[q];
		}	
}
if(max1>max2)
{
	cout<<"1"<<" "<<max1;
}
else
{
	cout<<"2 "<<max2;
}
return 0;

}

WHAT IS WRONG WITH THIS???

#include<stdio.h>
int max=0,i=0;
int main()
{

int n;
scanf("%d",&n);


while(n!=0)
{
	
	int x,y;
	scanf("%d %d",&x,&y);
	
	if((x-y)>max)
	{
		max=(x-y);
		i=1;
	}
	if((y-x)>max)
	{
		
		max=(y-x);
		i=2;
	}
	
	
	n=n-1;
}


printf("%d %d",i,max);

return 0;

}

WHATS WRONG WITH MY ANSWER.

#include <stdio.h>
#include <stdlib.h>
#define PLAYER1 1
#define PLAYER2 2
//this program is to count scores of two in a game for N round and declaring winner.
int main()
{
int n,si,ti;
int L1=0,L2=0;
scanf("%d",&n);
while(n–){
scanf("%d %d",&si,&ti);
if( (si-ti) > L1 ? (L1=si-ti):0){
}
else if ((ti-si)>L2 ? (L2=ti-si) : 0);
}
if(L1>L2) printf("%d %d",PLAYER1,L1);
else printf("%d %d",PLAYER2,L2);
return 0;
}

Can any one tell why my submission is wrong.
CodeChef: Practical coding for everyone.

#include

using namespace std ;

int main(){
int i=1,p1,p2,n,lead=0,maxlead1=0,maxlead2=0;
cin >> n;
while(i<=n){
cin >> p1 >> p2 ;
lead = lead + p1-p2 ;
if(p1-p2>maxlead1){maxlead1=p1-p2;}
if(p2-p1>maxlead2){maxlead2= p2-p1;}
i++ ;
}
if(lead>0){
cout << “1” << " " << maxlead1 << endl;
}
else{
cout << “2” << " " << maxlead2 << endl;
}
return 0;
}

what is wrong here?

lead = lead + p1-p2

This seems wrong to me since lead in one round is independent of other/previous rounds. MEaning, if 1 had lead of 50 in round one, and next round scores are Player1- 250, player2 -260 then elad of 2 will be 10. But your statement will do lead = 50(lead) -10 (p1-p2)