TLG - Editorial

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.
https://www.codechef.com/viewsolution/12824863.

#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)

Greetings!
May I ask for an optimal test case for this problem?
all the test cases that I use are confirmed but I am still getting wrong answer on submission
and I need to check if I am doing wrong and where.
Best Regards.
Robert.

Here is my code:
https://www.codechef.com/viewsolution/12893871


Hi, the problem with your code is that it only gives the output result of the last scores input in it. You need to give the result from all of the rounds’ scores input.

1 Like

import java.util.*;

class {

public static void main(String[] args)

{

Scanner sc=new Scanner(System.in);

int t=sc.nextInt();

int p11[]=new int[t];

int p22[]=new int[t];

if(t<=10000)

{

for(int i=0;i<t;i++)

{

int p1=sc.nextInt();

int p2=sc.nextInt();

p11[i]=(p1-p2);

p22[i]=(p2-p1);

}}

Arrays.sort(p11);

Arrays.sort(p22);

if(p11[t-1]>p22[t-1])

{
int k=1;

System.out.print(k+" "+p11[t-1]);

}

else{

int l=2;

System.out.print(l+" "+p22[t-1]);}

}
}

This is my code. its working fine with the sample test but is giving it wrong answer.

no use of array is required

#include
#include
//#include
#include<math.h>
#include
#include
using namespace std;
int main()
{
int t;
cin>>t;
vector< pair<int,int> > v;
for(int i=0;i<t;++i)
{
int si,ti,winner,lead;
cin>>si>>ti;
winner=(si>ti)?(1):(2);
lead=abs(si-ti);
v.push_back(make_pair(lead,winner));
}
sort(v.begin(),v.end(),greater< pair<int,int> >());
cout<<v[0].second<<" "<<v[0].first<<endl;
v.clear();
return 0;
}

Code Works fine. why codechef showing Wrong Answer??

import java.util.;
import java.io.
;
class lead{
public static void main(String args[]){
Scanner t = new Scanner(System.in);
int n = t.nextInt();//no. of rounds
int i, winner=0, max;
int a[] =new int[n];
int b[] =new int[n];
int c[] = new int[n];
for(i=0;i<n;i++){
a[i] = t.nextInt();
b[i] = t.nextInt();
}

	int a1[] =new int[n];
	a1[0] = 0;
	int b1[] =new int[n];
	b1[0] = 0;


	for(i=0;i<n;i++){
		a1[i] = a1[i] + a[i];
		b1[i] = b1[i] + b[i];
	}


		for(i=0;i<n;i++)
		{
		if(a1[i]>b1[i]){
			c[i] = a1[i]-b1[i];
		}
		else{
			c[i] = b1[i]-a1[i];
		}

	}
	max = c[0];
	for(i=0;i<n;i++)
		if(c[i]>max)
			max = c[i];


			for(i=0;i<n;i++)
		{
		if(a1[i]>b1[i]){
			winner = 1;
			if(c[i]==max)
				break;
		}
		else{
			winner = 2;
			if(c[i]==max)
				break;
		}

	}

	System.out.print(winner+ " ");
	System.out.println(max);

}

}

#include<stdio.h>
int main()
{
int n,i,leader,lead=0;
scanf("%d",&n);
int array1[n],array2[n];
for(i=0;i<n;i++)
{

    scanf("%d%d",&array1[i],&array2[i]);
    if(array1[i]>array2[i])
    {
        if(array1[i]-array2[i]>lead)
        {
            lead=array1[i]-array2[i];
            leader=1;
        }
    }
    else{
         if(array2[i]-array1[i]>lead)
        {
            lead=array2[i]-array1[i];
            leader=2;
        }
    }
}
printf("%d %d",leader,lead);

return 0;
}

sir why it give wrong answer pledge help me