TLG - Editorial

@msrshahrukh @anantsaksena89

Try with:

3

20 100

20 100

1000 0

The result should be player 1 with (1000+20+20)-(100+100)=840 lead points.

Your program gives player 1 with 1000 lead points.

2 Likes

whats wrong with my code :the codechef compiler says wrong ans

#include<stdio.h>
int main()
{
int a,b,i,lead1=0,lead2=0;
scanf("%d",&i);
while(i>0)
{
scanf("%d%d",&a,&b);

  if((a-b)>lead1)
     lead1=a-b;
  if((b-a)>lead2)
     lead2=b-a;
i--;

}
if(lead1>lead2)
printf(“1 %d\n”,lead1);
else
printf(“2 %d\n”,lead2);
return(0);
}

I have written program in python and its showing NZEC.

The Lead Game:

i = 0

score_dif= 0
p1_score,p2_score = 0,0

while True:
rounds = int(raw_input())
if rounds <= 10000:break
else : continue
while i < rounds :

p1_score,p2_score = map(int, raw_input().split())
if (1 <= p1_score <= 1000) and (1 <= p2_score <= 1000) and (p1_score != p2_score):
	lead = p1_score - p2_score
	if p1_score > p2_score and lead > score_dif:
		score_dif = lead
    		
	elif p1_score < p2_score and abs(lead) > score_dif:
		score_dif = lead
   		i += 1	
		
	
else : continue

if score_dif >= 0:
print “1”, score_dif
else:
print “2”, abs(score_dif)

my code is working but it is saying false

include <stdio.h>

int main()
{
int a,d,i,min=-1,e;
scanf("%d",&a);
int b[a],c[a];
for(i=0;i<a;i++)
{
scanf("%d %d",&b[i],&c[i]);

}
for(i=0;i<a;i++)
{
if(c[i]>b[i])
{
d=c[i]-b[i];
if(d>min)
min=d;
if(d==min)
{
e=2;
}

}
if(c[i]<b[i])
{
    d=b[i]-c[i];
    if(d>min)
    min=d;
    if(d==min)
    {
        e=1;
    }
}

}
printf("%d %d",e,min);
return 0;

}

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int n,j=1,f=0,t,k;
vector v;
scanf("%d",&n);
v.push_back(0);
for(int i=0;i<n;i++)
{
scanf("%d %d",&f,&k);
v.push_back(f);
v.push_back(k);
}
k=0;f=0;
for(int i=1;j<=n;i+=2,j++)
{
if(v[i]>v[i+1])
{
k=v[i]-v[i+1];
if(k>f)
{
t=1;
f=k;
}
}
else
{
k=v[i+1]-v[i];
if(k>f)
{
t=2;
f=k;
}
}
}
printf("%d %d\n",t,f);
return 0;
}

My code is giving the correct answer for all the testcases ive manually inputed and is still not getting accepted, please check it out and if there’s a mistake, cam somebody point it out ? !

@beroul, no it shouldn’t.

with the input:
3
20 100
20 100
1000 0

player 1 has the maximum lead of a 1000.
hence the output would be:
1 1000

2 Likes

I did it without use of arrays in a much small way.
The problem statement is pretty much vague. We need to sum up all the points up to the current round, find the lead at the end of the round, compute the lead and display the maximum lead out of the calculated leads and the the corresponding winner.

I did it in a small way. Check that out.
Correct solution to TLG

2 Likes

include

int main() {
int a,b,x,y,n,m,h,g;
scanf("%d",&a);
for(b=1;b<=a;b++)
{
scanf("%d %d",&x,&y);
if(x>y)
{
n = x-y;
m=1;
}
else
{
n = y-x;
m=2;
}
if(n>=h)
{
g=m;
h=n;
}
}
printf("%d %d",g,h);
return 0;
}

#include <stdio.h>

int main()
{
int a , i,j;
scanf("%d",&a);
int arr[a][3];

for (i=0;i<a;i++)
{
    for (j=0;j<2;j++)
        scanf("%d",&arr[i][j]);
}
for (i=0;i<a;i++)
{
    if (arr[i][0]> arr[i][1])
    {
        arr[i][2] = arr[i][0] - arr[i][1];
    }
    else if (arr[i][0]<arr[i][1])
    {
        arr[i][2] = arr[i][1] - arr[i][0];
    }
}
int *max = &arr[0][2];

for (i=0;i<a;i++)
{
    for ( j=i+1; j<a;j++)
    {
         if (*max < arr[j][2])
            *max = arr[j][2];
    }


}
if (*(max-2)> *(max-1))
printf("%d %d",1, *max);
if (*(max-2)< *(max-1))
printf("%d %d", 2 , *(max));
return 0;

}

Please Check my code.
Thanks

1 Like

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[i][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[i]<S[i+1])
{
maxs=S[i+1];
}
if(T[i]<T[i+1])
{
maxt=T[i+1];
}
}
if(maxs>maxt)
{
printf(“1\t%d”,maxs);
}
else
{
printf(“2\t%d”,maxt);
}
}
else
exit(0);
return 0;
}

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[i]==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?

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

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

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[i]=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\n",1,max);
    }
    else
    {
        printf("%d %d\n",2,min);
    }
    
    return 0;
  }

Happy Coding !!

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[i],&t[i]);
l[i]=s[i]-t[i];
if(l[i]<0)
l[i]=(-1)*l[i];
}
m=l[0];
for(i=1;i<N;i++)
{
if(l[i]>m){
m=l[i];
count=i;
}
}
if(s[count]>t[count])
w=1;
else
w=2;
printf("%d %d",w,m);
return 0;
}

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

1 Like

@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… CodeChef: Practical coding for everyone

#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[i]>S2[i])
{L[i]=S1[i]-S2[i];
winner[i]=1;
}
else
{L[i]=S2[i]-S1[i];
winner[i]=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.??

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[i] = Integer.parseInt(input1[0]);
		p2[i] = Integer.parseInt(input1[1]);
		leads[i] = Math.abs(p1[i] - p2[i]);
		if (max_lead < leads[i]) {
			max_lead = leads[i];
			pos = i;
		}
	}
	if (p1[pos] > p2[pos])
		System.out.println(1 + " " + max_lead);
	else
		System.out.println(2 + " " + max_lead);
}

}

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