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

×

Lead Game: Can someone give other test cases so I can find out what's wrong?

import java.io.*;
import java.lang.Math;

class Lead_Game
{
    public static void main (String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        int max = 0;
        String[] ar = {};
        int p1 = 0;
        int p2 = 0;
        int x = 0,y = 0;
        for(int i = 0;i < t; i++){
            ar = (br.readLine()).split(" ");
            p1 = Integer.parseInt(ar[0]);
            p2 = Integer.parseInt(ar[1]);
            if(Math.abs(p1-p2) > max){
                max = Math.abs(p1-p2);
                x = p1;
                y = p2;
            }
            else{
                continue;
            }
        }
        if(x > y){
            System.out.println("1 "+max);
        }
        else{
            System.out.println("2 "+max);
        }
    }
}

asked 02 May '15, 19:58

coderboy91's gravatar image

0★coderboy91
11
accept rate: 0%

edited 02 May '15, 20:02


TRY 5 50 20 10 90 80 20 90 10 50 20: your ans-2 80: corr ans-1 120: read the question again: have fun:good luck:

link

answered 02 May '15, 21:09

monu7z's gravatar image

2★monu7z
11
accept rate: 0%

You have to keep on updating the scores of player 1 and 2 and check at each step the difference( who's difference is more at any step is the winner).

link

answered 02 May '15, 21:56

anupam_datta's gravatar image

4★anupam_datta
378524
accept rate: 7%

edited 02 May '15, 21:57

5 50 20 10 90 80 20 90 10 50 20

in the above test case can you please xplain how the answer should be 1 120

link

answered 01 Jun '15, 23:16

write2diba's gravatar image

2★write2diba
311
accept rate: 0%

n=input() w=1; top=0 ps1=0 ps2=0 while (n>0): inp=raw_input(); p1,p2=inp.split(); ps1+=int(p1); ps2+=int(p2); diff=ps1-ps2; Abs=abs(diff); if(Abs>top): top=Abs; if diff>0: win=1; else: win=2; n-=1; print str(w)+" "+str(top); ''' can anyone please tell me whats wrong with my code. It is giving wrong answer but the code is correct in each test case'''

link

answered 08 Nov '15, 22:52

sharma16aug's gravatar image

1★sharma16aug
161
accept rate: 33%

"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." In the question it says maximum lead in any round so why had to add after every round. Similar problem is with me.

https://www.codechef.com/viewsolution/12516137

link

answered 12 Jan '17, 10:48

lksinghal's gravatar image

1★lksinghal
1
accept rate: 0%

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:

×1,142
×9

question asked: 02 May '15, 19:58

question was seen: 1,306 times

last updated: 12 Jan '17, 10:48