You are not logged in. Please login at www.codechef.com to post your questions!

×

TLG - Editorial

PROBLEM LINK:

Practice

Author: ADMIN

Editorialist: SUSHANT AGARWAL

DIFFICULTY:

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.

asked 17 Dec '14, 16:00

sushant96's gravatar image

0★sushant96
21368
accept rate: 0%

edited 02 Jan '15, 17:25

admin's gravatar image

0★admin ♦♦
19.3k348495534

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

My answer: link text

(23 Aug '16, 14:26) prkhrsrvstv12★

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

link

answered 23 Jul '16, 21:32

shreya_0296's gravatar image

0★shreya_0296
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) lohit_973★

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

pranzy95's gravatar image

2★pranzy95
1
accept rate: 0%

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

}

link

answered 08 May '17, 01:52

drjaat's gravatar image

2★drjaat
267111
accept rate: 6%

edited 08 May '17, 09:58

I don't think there is need of four different arrays, this thing can be done using just three variables

link

answered 09 Jan '15, 13:01

codepad's gravatar image

2★codepad
1
accept rate: 0%

I think my solution is short and indented.

http://www.codechef.com/viewsolution/5886009

link

answered 13 Jan '15, 12:37

jaksparo's gravatar image

2★jaksparo
1112
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;

}

link

answered 22 Mar '15, 00:35

ashkmr574's gravatar image

2★ashkmr574
5
accept rate: 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<Integer, Integer> mp = null;

    try{
        sc = new Scanner(System.in);
        num = sc.nextInt();
        //sc.nextLine();
        mp = new HashMap<Integer, Integer>();
        for(int i = 0; i<num ; i++  ){

            //String[] s = sc.nextLine().split(" ");

            int pl1 = sc.nextInt(); //Integer.parseInt(s[0]);
            int pl2 = sc.nextInt();  //Integer.parseInt(s[1]);

            mp.put(Math.abs(pl1-pl2), pl1>pl2 ? 1 : 2); 
        }
        findWinner(mp);
    }
    catch(Exception e){
        e.printStackTrace();
    }
}


private static void findWinner(Map<Integer, Integer> mp){

    Set<Integer> key = null;
    Iterator<Integer> 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();
    }

}

}

link

answered 29 May '15, 17:28

anantsaksena89's gravatar image

0★anantsaksena89
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) anantsaksena890★

include <iostream>

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){
            if(lead<(a-b)){
                name=1;
                lead=a-b;
            }

        }
        else{
            if(lead<(b-a)){
                name=2;
                lead=b-a;
            }
        }


    }
    printf("%d %d",name,lead);

return 0;

}

I am getting a wrong answer dont know why. Please help.

link

answered 01 Jul '15, 20:48

aronzx's gravatar image

3★aronzx
1
accept rate: 0%

include<stdio.h>

main() {

int t;
int lead[2]={0};
scanf("%d",&t);
while(t--)
{

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

    if(a>b  && (a-b)>lead[0])
    {
        lead[0]=a-b;
    }
    if(a<b && (b-a)>lead[1])
    {
        lead[1]=b-a;
    }


}

if(lead[0]>lead[1])
    printf("1 %d",lead[0]);
else 
    printf("2 %d",lead[1]);

return 0;

}

I dont understand whats wrong in it ..plz help

link

answered 03 Jul '15, 03:43

msrshahrukh's gravatar image

2★msrshahrukh
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.

link

answered 10 Oct '15, 19:31

sumeet15182's gravatar image

1★sumeet15182
1
accept rate: 0%

12345 ... 9next »

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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