TLG - Editorial

array
easy
editorial

#21

what is wrong with this can any one please help me

#include<stdio.h>
#include<stdlib.h>
int main()
{
int N,A[1000][2];
scanf("%d",&N);
int S[N],T[N];
if(N<=1000)
{
int i,j;
for(i=0;i<N;i++)
{
for(j=0;j<2;j++)
{
scanf("%d%d",&A*[j]);
}
}
for(i=0;i<N;i++)
{
S[N]=A[N][0]-A[N][1];
T[N]=A[N][1]-A[N][0];
}
int maxs,maxt;
maxs=S[0];
maxt=T[0];
int Temp;
for(i=0;i<N-1;i++)
{
if(S*<S[i+1])
{
maxs=S[i+1];
}
if(T*<T[i+1])
{
maxt=T[i+1];
}
}
if(maxs>maxt)
{
printf(“1 %d”,maxs);
}
else
{
printf(“2 %d”,maxt);
}
}
else
exit(0);
return 0;
}


#22

import java.lang.Math;
public class Main{
public static void main(String args[]) {

    Scanner s = new Scanner(System.in);

int n = s.nextInt();
int wins[] = new int[n];
int lead[] = new int[n];
int cur_lead; int cur_win; int t=n; int win_round=0; int winner=0;

for(int z=0; z<n; z++){
int p1 = s.nextInt();
int p2 = s.nextInt();
cur_win = (p1>p2)?1:2; 
cur_lead = Math.abs(p1-p2);
wins[z]=cur_win;
lead[z]=cur_lead;
} 

int max_lead = lead[0];

for(int j=1;j<t;j++){
max_lead = Math.max(max_lead, lead[j]);
} 

int i;

for(i=0; i<t; i++){
if (lead*==max_lead)
{ win_round=i; break;}
else continue;
}

winner = wins[win_round];
System.out.println(""+winner+" "+max_lead);
System.exit(0);
}
}

Above code is reported wrong though working correctly. Can anyone please point out the mistake?


#23

Can anyone explain to me what’s wrong in my code ? pls
#include<bits/stdc++.h>
using namespace std;
int main()
{ int t,a,b,i,p=0;
int s1=0,s2=0,s3=0,s4=0;

cin>>t;

for(i=0;i<t;i++)
{ cin>>a>>b;

 if (a>b)
{  s1=a-b;
   if(s1>s2)
   {
     p=1;       	   
  s2=a-b;
         
 
  }
  } else  
   { s3=b-a;
      if(s3>s4)
	  {
			   
   s4=b-a;
       
      } 
  }
}

 if (s2>s4)
  {  
  cout<<p<<" "<<s2;
  }
  else 
 {
   
  cout<<p<<" "<<s4;

}
return 0;
}


#24

#include
using namespace std;
int main()
{
int rem,lead=0,leader=0,player;
int n;
cin>>n;
for(int i=0;i<n;i++)
{

	int a,b,rem=0;
	cin>>a>>b;
	if(a>b)
		{rem=a-b;
		player=1;}
	else
		{rem=b-a;
		player=2;
		}
	if(rem>lead)
	{lead=rem;
	leader=player;
	}

}
cout<<leader<<" "<<lead;
	
    return 0;

}
I am getting correct answer on gcc but when i am submitting here i am getting wrong answer.whats wrong in the above code?


#25

This is Easy Solution For This Problem.I Tried to make it more understable using comment over every Line.

#include stdio.h
#include algorithm
#include stdlib.h



  int main()
  {
    int t,a,b,c=0,d=0;
    int arr[10005];
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
       scanf("%d%d",&a,&b);
       c=c+a;               //This Will Save All the Score Of Player 1 in all round
       d=d+b;               //This Will Save All the Score Of Player 1 in all round
       arr*=c-d;          //This store lead in each round and save it into a array
    }
    
    int max=*std::max_element(arr,arr+t);  //This will find the maximum lead by Player 1
    int min=*std::min_element(arr,arr+t); //This will find the max lead by Player 2
    
    min=abs(min);       //This Will take the positive value of player 2 as it will be negative
    if(max>min)         //Check If Player1 Lead>Player 2 Lead if Yes Print 1 else 2
    {
        printf("%d %d
",1,max);
    }
    else
    {
        printf("%d %d
",2,min);
    }
    
    return 0;
  }

Happy Coding !!


#26

Plzz can someone say , what’s wrong with my code ??

#include<stdio.h>
#define MAX 10000
int main()
{
int N,i,m,w,s[MAX],t[MAX],l[MAX],count;
scanf("%d",&N);
for(i=0;i<N;i++)
{
printf(“enter the scores”);
scanf("%d%d",&s*,&t*);
l*=s*-t*;
if(l*<0)
l*=(-1)l;
}
m=l[0];
for(i=1;i<N;i++)
{
if(l*>m){
m=l*;
count=i;
}
}
if(s[count]>t[count])
w=1;
else
w=2;
printf("%d %d",w,m);
return 0;
}


#27

#include <stdio.h>

int main(void) {

int n,i,in1,in2,count=0,winner=0;
scanf("%d",&n);

for(i=0;i<n;i++)
{
	scanf("%d%d",&in1,&in2);
	if(in1>in2)
	{
		if((in1-in2)>count)
		{
		    count=in1-in2;
		    winner=1;
		}
	}
	else
	{
		if((in2-in1)>count)
		{
		    count=in2-in1;
		    winner=2;
		}
	}
}
printf("%d %d",winner,count);

return(0);

}

what is wrong with my solution??


#28

@shreya_0296
You are deciding he winner of a round based on the scores of that round it self…
But according to the problem statement… we have to decide the winner based on the cumulative scores…
i.e. if we want to decide the winner of round 3… then we need to sum up all the scores of round 1 and round 2 and round 3 of both players… now we need to decide the winner…

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


#29

#include
using namespace std;

int main() {
int round;
cin>>round;
int S1[round-1],S2[round-1];
int L[round-1];
int winner[round-1];
int n;
for(int k=0;k<round;k++)
{
cin>>S1[k]>>S2[k];
}
for(int i=0;i<round;i++)
{
if(S1*>S2*)
{L*=S1*-S2*;
winner*=1;
}
else
{L*=S2*-S1*;
winner*=2;
}
}
for(int j=0;j<round;j++)
{
if(L[0]<=L[j])
{ L[0]=L[j];
n=j;
}

}
cout<<winner[n]<<" "<<L[0];
return 0;

}

Why Solution is showing wrong answer despite it shows correct output.??


#30

I have tried with the given logic the problem wants us to provide and is working fine with my test cases. But still I am getting a wrong answer. Here’s my code.
import java.io.*;

public class CodeChef {

public static void main(String[] args) throws Exception {
	BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
	int size = Integer.parseInt(read.readLine());
	int[] p1 = new int[size];
	int[] p2 = new int[size];
	int[] leads = new int[size];
	int pos = 0;
	int max_lead = leads[0];
	for (int i = 0; i < size; i++) {
		String[] input1 = read.readLine().split(" ");
		p1* = Integer.parseInt(input1[0]);
		p2* = Integer.parseInt(input1[1]);
		leads* = Math.abs(p1* - p2*);
		if (max_lead < leads*) {
			max_lead = leads*;
			pos = i;
		}
	}
	if (p1[pos] > p2[pos])
		System.out.println(1 + " " + max_lead);
	else
		System.out.println(2 + " " + max_lead);
}

}


#31

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


#32

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


#33

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


#34

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


#35

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


#36

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


#37

AC Solution : https://www.codechef.com/viewsolution/11279231


#38

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*-arr2*)>0 &&(arr1*-arr2*>score)){
			score=arr1*-arr2*;
			player=1;
		}
		else if((arr1*-arr2*<0 && Math.abs(arr1*-arr2*)>score)){
			score=arr2*-arr1*;
			player=2;
		}
	}
	System.out.print(player);
	System.out.print(" ");
	System.out.print(score);
	
}

}


#39

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;i0) { max*=s*-t*; winer*=1;

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



        }
}
        diff=max[0];
        win=winer[0];
        for(i=0;i=diff)
            {
                diff=max*;
                win=winer*;
            }

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

       return 0;
}

please tell where i m going wrong !


#40

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*=s.nextInt();
		k*=s.nextInt();
		if(m*>=1&&m*<=1000&&k*>=1&&k*<=1000){
		if(m*>k*)   //for player 1
		{a[t]=m*-k*;
			t++;}
		else
			{b[l]=k*-m*;  //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