×

# TLG - Editorial

Editorialist: SUSHANT AGARWAL

EASY

# PREREQUISITES:

Basic looping,Arrays

# PROBLEM:

At the end of each round the leader and her current lead are calculated. Once all the rounds are over the player who had the maximum lead at the end of any round in the game is declared the winner.

# EXPLANATION:

Create two arrays(Player1-Stores the scores of player 1 in all the rounds)[a1,a2,a3....an] and (Player2-Stores the scores of player 2 in all the rounds)[b1,b2,b3...bn].

Create a third array "Lead" such that the i'th element of Lead is ((a1+a2...+ai) - (b1+b2...bi)). Create a fourth array "modulus lead" such that the i'th element of this array is the modulus of the i'th element of "Lead".

Find the maximum element of "modulus lead".This is the maximum lead attained by the winner.If the element in the corresponding position of "lead" is positive then player 1 is the winner,otherwise player 2 is.

# EDITORIALIST'S SOLUTION:

Editorialist's solution can be found here.

21368
accept rate: 0%

19.3k348495534

What is wrong with my code? It is working fine with sample input, but on submitting it codechef says 'Wrong Answer'.

(23 Aug '16, 14:26)

12345 ... 9next »

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

11
accept rate: 0%

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.

(24 Jul '16, 14:35) 3★
 1 https://discuss.codechef.com/questions/58753/tlg-editorial/83486 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. link This answer is marked "community wiki". answered 06 Mar '17, 20:17 2★pranzy95 1 accept rate: 0%
 1 import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*; class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); int player=0,max; int almax=0,playerf=0; while(t-->0){ int count=0; int a = scan.nextInt(); int b = scan.nextInt(); if(a>b){ max=a-b; player=1; } else{ max=b-a; player=2; } //finding maximum if(max>=almax){ almax=max; playerf=player; } } System.out.println(playerf+" "+almax); }  } answered 08 May '17, 01:52 2★drjaat 267●1●11 accept rate: 6%
 0 I don't think there is need of four different arrays, this thing can be done using just three variables answered 09 Jan '15, 13:01 2★codepad 1 accept rate: 0%
 0 I think my solution is short and indented. http://www.codechef.com/viewsolution/5886009 answered 13 Jan '15, 12:37 2★jaksparo 1●1●1●2 accept rate: 0%

what is wrong with my code??

# include<stdio.h>

int main() { long n,s1,s2,max,i,d,m; scanf("%ld",&n); max=0; for(i=1;i<=n;i++) { scanf("%ld%ld",&s1,&s2); if(s1>s2) { d=s1-s2; if(d>max) { max=d; m=1; } } else { d=s2-s1; if(d>max) { max=d; m=2; } }

   }
printf("%ld %ld\n",m,max);
return 0;


}

5
accept rate: 0%

 0 import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Set; class LeadGame { public static void main(String args[]){ int num = 0; Scanner sc = null; Map mp = null; try{ sc = new Scanner(System.in); num = sc.nextInt(); //sc.nextLine(); mp = new HashMap(); for(int i = 0; ipl2 ? 1 : 2); } findWinner(mp); } catch(Exception e){ e.printStackTrace(); } } private static void findWinner(Map mp){ Set key = null; Iterator itr = null; int large = -1; try{ if(mp!=null) key = mp.keySet(); itr = key.iterator(); while(itr.hasNext()){ int lead = itr.next(); if(lead > large) large = lead; } System.out.println(mp.get(large)+" "+large); } catch(Exception e){ e.printStackTrace(); } }  } answered 29 May '15, 17:28 1 accept rate: 0% 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. (29 May '15, 17:29)

# include<stdio.h>

using namespace std;

int main() { int num,a,b,lead=0,i,name; scanf("%d",&num);

    for(i=0;i<num;i++){
scanf("%d",&a);
scanf("%d",&b);
if(a>b){
name=1;
}

}
else{
name=2;
}
}

}

return 0;


}

3★aronzx
1
accept rate: 0%

# include<stdio.h>

main() {

int t;
scanf("%d",&t);
while(t--)
{

int a,b;
scanf("%d%d",&a,&b);

{
}
{
}

}

else

return 0;


}

I dont understand whats wrong in it ..plz help

1
accept rate: 0%

n=int(input()) b=[] c=[] for i in range(n): m=list(map(int,input().split())) s=m[0]-m[1] c.append(s) p=abs(m[0]-m[1]) b.append(p) q=max(b) for j in c: if q==j: print(1,q) break else: print(2,q)

#### i have written the code in python..i am getting the desired output but it is getting wrong at the submission..please help me out.

1
accept rate: 0%

12345 ... 9next »

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,010
×3,407
×804

question asked: 17 Dec '14, 16:00

question was seen: 16,075 times

last updated: 13 Sep, 18:55