CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » The Lead Game

The Lead Game

Problem code: TLG

  • Submit
  • All Submissions

All submissions for this problem are available.

The game of billiards involves two players knocking 3 balls around on a green baize table. Well, there is more to it, but for our purposes this is sufficient.

The game consists of several rounds and in each round both players obtain a score, based on how well they played. Once all the rounds have been played, the total score of each player is determined by adding up the scores in all the rounds and the player with the higher total score is declared the winner.

The Siruseri Sports Club organises an annual billiards game where the top two players of Siruseri play against each other. The Manager of Siruseri Sports Club decided to add his own twist to the game by changing the rules for determining the winner. In his version, 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.

Consider the following score sheet for a game with 5 rounds:

    Round     Player 1       Player 2

      1             140                 82
      2              89                 134 
      3              90                 110 
      4              112              106
      5              88                  90 

The total scores of both players, the leader and the lead after each round for this game is given below:

    Round      Player 1       Player 2     Leader     Lead

      1               140           	 82        Player 1     58
      2               229           	216       Player 1     13
      3               319           	326       Player 2      7
      4               431           	432       Player 2      1
      5               519           	522       Player 2      3

The winner of this game is Player 1 as he had the maximum lead (58 at the end of round 1) during the game.

Your task is to help the Manager find the winner and the winning lead. You may assume that the scores will be such that there will always be a single winner. That is, there are no ties.

Input

The first line of the input will contain a single integer N (N <= 10000) indicating the number of rounds in the game. Lines 2,3,...,N+1 describe the scores of the two players in the N rounds. Line i+1 contains two integer Si and Ti, the scores of the Player 1 and 2 respectively, in round i. You may assume that 1 <= Si <= 1000 and 1 <= Ti <= 1000.

Output

Your output must consist of a single line containing two integers W and L, where W is 1 or 2 and indicates the winner and L is the maximum lead attained by the winner.

Example

Input:

5
140 82
89 134
90 110
112 106
88 90

Output:

1 58


Author: admin
Date Added: 28-07-2009
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

gaurav17 @ 29 Jul 2009 09:16 PM

i dunno why every time i am getting the wrong answer...its working fine with the given input above...

triplem @ 29 Jul 2009 10:17 PM

Try some other inputs then :)

username115 @ 29 Jul 2009 10:37 PM

I'm getting the same problem, and I have tried other inputs and got no problems from them either...

i0exception @ 29 Jul 2009 11:44 PM

Well, instead of trying random test cases, you should try finding corner-cases and test your code on those.

chang @ 30 Jul 2009 06:47 AM

isnt the question is to find the maximum difference of scores among all rounds ? is der more to it ?

username115 @ 30 Jul 2009 10:26 PM

Is there any addition information about how the output should be formatted? All the test cases I've tried (including corner cases) have output a correct answer as far as I can tell, but I still get "wrong answer" when I submit.

admin 2 @ 30 Jul 2009 10:36 PM

You just have to output the two integers as specified in the statement.

kush87 @ 9 Aug 2009 03:34 PM

hey....the question is only about finding the maximum difference of scores among all rounds......and the player who won that particular round? or is there anything else?

havefun @ 12 Aug 2009 08:37 AM

@admins hv a look at test data something is fishy here

admin 2 @ 12 Aug 2009 10:01 AM

The test data is fine. You can see that there have been a lot of successful submissions for this problem.

When I submit, it says "time

udayabhanu @ 20 Aug 2009 01:45 PM
When I submit, it says "time limit exceeded", but my program locally runs in 0 milliseconds time? I can't believe this.

The code is run against

admin @ 20 Aug 2009 01:46 PM

The code is run against larger testcases when you submit, not just the test cases provided in the sample input/output.

I ran it with 10000 inputs

udayabhanu @ 20 Aug 2009 01:50 PM
I ran it with 10000 inputs and the worst case for my implementation, which is, first player getting -i and second one getting -2i marks in each round. Still my machine reports 0 ms.

Sorry, first player gets i

udayabhanu @ 20 Aug 2009 01:53 PM
Sorry, first player gets i mod 1001, and second one gets 2i mod 1001 points. I suspect something is wrong with the test env, or something. Are you sure that the input is at max, 10K rounds and the score is max 1000, in each round.

You are not taking input in

admin @ 20 Aug 2009 01:58 PM

You are not taking input in accordance with the problem statement. Please re-read the problem statement with regard to how input is taken.

Hmm... Sorry, the time limit

udayabhanu @ 20 Aug 2009 02:25 PM
Hmm... Sorry, the time limit was since, I was expecting more than one test case in the input. That is fine now. However, I have a doubt in the problem stmt. When player1 won round 1 and round2 also, should we accumulate the lead, at end of round2 to be l1 + l2, or, just take the max of these two, and use that as the diff?

The example given in the

triplem @ 20 Aug 2009 04:56 PM

The example given in the problem statement demonstrates this clearly.

Does the o/p must contain a

crazysaikat @ 20 Aug 2009 05:25 PM
Does the o/p must contain a space between two o/p. Every time i am getting wrong answer. I don't know why. Please check.

i have given many inputs-all

akhilesh890 @ 20 Aug 2009 06:37 PM
i have given many inputs-all works fine;but here it shows wrong. ithis is my code;someone please rectify the logical error: #include using namespace std; int i; int max( int[] , int ); int main() { int rounds; cin >> rounds; int *c,*d,r=0,s=0,a,b; c = new int[rounds]; d = new int[rounds]; for ( i = 0 ; i < rounds ; i++ ) { cin >> a >> b; if ( a > b ) { c[r] = a-b; r++; } else { d[s] = b-a; s++; } } int m = max ( c , r ); int n = max ( d , s ); if ( m > n ) cout <<"1"<<' '<< m << endl; else cout <<"2"<<' '<< n << endl; } int max( int p[] , int n ) { int big; big = p[0]; for ( i = 1 ; i <= n ; i++ ) { if ( big < p[i] ) big = p[i]; } return big; }

Please don't post code here.

admin @ 20 Aug 2009 07:53 PM

Please don't post code here.

As for the actual problem

triplem @ 21 Aug 2009 06:56 AM
As for the actual problem with your code, you are not interpreting the input correctly. Read the example in the problem statement.

Got Wrong Answer !!! not

its_bpk @ 21 Aug 2009 10:27 AM
Got Wrong Answer !!! not sure...Problem looks straightforward ... unable to make out what I have missed out on? any suggestions ?

thanks stephen...

akhilesh890 @ 21 Aug 2009 06:07 PM
thanks stephen...

can anyone tell what can b

mshshetty @ 4 Sep 2009 02:29 AM

can anyone tell what can b the corner cases 4 tis problem.. i m geting rong ans every time.. i have checked my pgm by giving 10000 inputs b using rand func.. its working fine.. please help..

 

You might want to recheck

admin @ 4 Sep 2009 01:51 PM

You might want to recheck your algorithm. I don't think the answers you are getting on your random input tests are correct as well.

@admin: Please give some

sidharth @ 8 Sep 2009 04:22 AM

@admin: Please give some tough corner test cases to try out ...

My code is 90719. I am not

ron1988 @ 9 Sep 2009 01:54 AM

My code is 90719. I am not able to find mistake in my code. Its running properly for the inputs I entered.

But on submitting it shows wrong answer.

isn't the output given in the

sudeep @ 12 Sep 2009 08:49 PM

isn't the output given in the example wrong??

Example

Input:

5
140 82
89 134
90 110
112 106
88 90

Output:

1 58

shouldn't the output be

1 140

??

my programme is working fine

ankit_khedekar @ 12 Sep 2009 11:30 PM

my programme is working fine for the sample output on my pc

but when i try to submit i get this error


Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/html/codechefbeta/codechef/sites/all/modules/codechef_judge/codechef_judge.module:48 Stack trace: #0 /var/www/html/codechefbeta/codechef/sites/all/modules/codechef_judge/codechef_judge.module(48): SimpleXMLElement->__construct('admin<br />?<b>...') #1 /var/www/html/codechefbeta/codechef/modules/node/node.module(673): codechef_judge_nodeapi(Object(stdClass), 'validate', Array, NULL) #2 /var/www/html/codechefbeta/codechef/modules/node/node.module(809): node_invoke_nodeapi(Object(stdClass), 'validate', Array) #3 /var/www/html/codechefbeta/codechef/modules/node/node.pages.inc(65): node_validate(Array, Array) #4 /var/www/html/codechefbeta/codechef/includes/form.inc(766): node_form_validate(Array, Array) #5 /var/www/html/codechefbeta/codechef/includes/form.inc(714): form_execute_handlers('validate', Array, Array) #6 /var/www/html/codechefbeta/codechef/includes/form.inc(579): _form_validate(Array, Array, 'answer_node_for...') in /var/www/html/codechefbeta/codechef/sites/all/modules/codechef_judge/codechef_judge.module on line 48

what does this mean?

@Sudeep - no, the example is

triplem @ 13 Sep 2009 03:41 AM

@Sudeep - no, the example is correct, and there is a full explanation in the problem statement.

@Ankit This will be fixed

admin @ 13 Sep 2009 07:54 PM

@Ankit This will be fixed ASAP

 i am getting NZEC runtime

kartikeya1994 @ 15 Sep 2009 08:26 PM

 i am getting NZEC runtime error, using java , can you tell me the possible reasons?...

 

I am sure no array is going out of bound..(yes i am using arrays..)...

 

also is it because i am splitting my programme up into two methods?

 

Do i need to have all my methods and variables static?..i am using all non-static currently..

 i employed another method,

kartikeya1994 @ 15 Sep 2009 09:16 PM

 i employed another method, did the test inputs, got correct output, did random inputs( 10,000 ).....yet it says "wrong answer" when i sunmit.....i see no possible error in my code as it it short , sweet and simple..... can anyone help me out?... 93778 is my ID

One of the reasons for

admin @ 16 Sep 2009 01:17 PM
One of the reasons for getting a NZEC error would be that your program is throwing an exception which is not caught.

 doesnt 'throws IOException'

kartikeya1994 @ 16 Sep 2009 09:49 PM

 doesnt 'throws IOException' catch all exceptions?

 does it give different

kartikeya1994 @ 16 Sep 2009 10:17 PM

 does it give different random inputs every time or is there  a decided set of inputs...?

 

for the same code submission, i get a NZEC as well as 'wrong answer'  ...  :?

No, throws IOException will

admin @ 16 Sep 2009 10:24 PM
No, throws IOException will only catch exceptions related to input/output. The set of inputs is the same always.

any recommendations for

kartikeya1994 @ 16 Sep 2009 10:59 PM
any recommendations for catching all of them? try{ }catch(Exception e){} too doesnt work

do wrapper classes give

kartikeya1994 @ 16 Sep 2009 11:16 PM
do wrapper classes give exception while handling large data?...how do i resolve them?

i jus checked my code on my

rakshith_babu @ 17 Sep 2009 07:04 AM
i jus checked my code on my pc it works fine. but i'm gettin runtime error here.. can you explain the possible reason

@Rakshith You need to exit

admin @ 17 Sep 2009 01:57 PM
@Rakshith You need to exit with a return code of 0 indicating successful termination. You don't have a return 0 at the end of your code. @Kartikeya You can catch all exceptions using catch(Exception e), but if you do nothing in the catch, it doesn't help much.

can i use parseInt directly

kartikeya1994 @ 17 Sep 2009 09:35 PM
can i use parseInt directly or do i need to convert to Integer object and then to int?...does this give exceptions

whats the problem with the

jigar @ 21 Sep 2009 02:08 PM
whats the problem with the code chef my code is compiling properly but still is it showing me compilation errors as a result

Please read the FAQ and the

admin @ 21 Sep 2009 02:21 PM
Please read the FAQ and the help section at www.codechef.com/help

This must be a deceptive

dwitkowski @ 29 Sep 2009 01:11 AM

This must be a deceptive problem, because it seems so straightforward but my code is returning the wrong answer. Since they cannot tie in any particular round I can't see what it is I could be doing wrong.

Yes, this is a

triplem @ 29 Sep 2009 05:58 AM

Yes, this is a straightforward problem. I expect every one of the commenters who are getting the wrong answer are doing so because they haven't read what the input numbers actually mean.

please anyone help me out for

Bhairavi @ 29 Sep 2009 07:51 PM

please anyone help me out for this code in C++ or c or java..........,if i have submit this code then only i got the job so pls. do needful...........

please anyone help me out for

Bhairavi @ 29 Sep 2009 07:51 PM

please anyone help me out for this code in C++ or c or java..........,if i have submit this code then only i got the job so pls. do needful...........

pls can someone look at my

rampage @ 5 Oct 2009 04:01 PM

pls can someone look at my code and tell ,e what the problem is?

my solution id is 103449.

i have tried a lot of test cases and they all give the correct answer but its still not getting accepted.

leave it o_0  

rampage @ 5 Oct 2009 04:23 PM

leave it

o_0

 

@admin, timit limit is for

shaileshbhat @ 9 Oct 2009 08:25 AM

@admin,

timit limit is for processing or both printing and processing(generally not specific to this problem)

Both printing and processing.

admin @ 9 Oct 2009 01:48 PM

Both printing and processing.

those getting WA do note that

gaurav17 @ 24 Oct 2009 04:27 PM

those getting WA do note that in each round the previous scores are added

Hey can the admin tell what

shivam_gupta @ 26 Oct 2009 04:08 PM
Hey can the admin tell what is wrong with my code.??? Please help...!!! Coz the code works on my comp just fine..!

hey what happens if both get

subhranil @ 9 Nov 2009 11:55 AM

hey what happens if both get a lead equal to  the same max lead but in different rounds .. who is thwe winner ??

Read the last sentence that

triplem @ 9 Nov 2009 01:00 PM

Read the last sentence that comes before 'Input'.

i got result in 0.02 seconds

shanky89 @ 11 Nov 2009 12:43 PM

i got result in 0.02 seconds and accepted and still it is not showing my rank in submitted successfully windows

Yes it is..

triplem @ 11 Nov 2009 01:07 PM

Yes it is..

where

shanky89 @ 11 Nov 2009 03:16 PM

where

You're the first name on the

triplem @ 11 Nov 2009 04:32 PM

You're the first name on the second page?

hello my answer is coming

shailendra_ameta @ 11 Nov 2009 04:56 PM

hello

my answer is coming correct in my system but after submotting it is showing wrong answer...... y??

list = []t =

shailendra_ameta @ 11 Nov 2009 05:17 PM

list = []
t = int(raw_input())
while(t>0):
inp = raw_input().split()
m = int(inp[0])
n = int(inp[1])
d = m-n
list.append(d)
t -= 1
list.sort()
if abs(list[0]) > list[len(list)-1]:
w = 2
l = abs(list[0])
else:
w = 1
l = list[len(list)-1]
print w,l

pls anyone tell me what is the wrong in this code...This code is in python.

is it necessary to do any

Fright01 @ 13 Nov 2009 12:44 PM

is it necessary to do any catching of errors?

The input you are provided

triplem @ 13 Nov 2009 01:43 PM

The input you are provided will comply with the constraints in the problems statement.

I am reading this problem and

hiptobecubic @ 18 Nov 2009 02:17 AM

I am reading this problem and don't think anything crazy is happening. Can I ask, however, what "You may assume that 1 Si 1000 and 1 Ti 1000." is supposed to mean? Is round 1 always 1000 to 1000? I thought there were no ties?

That should say 1 <= Si <=

triplem @ 18 Nov 2009 03:09 AM

That should say 1 <= Si <= 1000 and 1 <= Ti <= 1000.

Chef, the I/O is often

udaydeep_1990 @ 25 Nov 2009 05:46 PM

Chef, the I/O is often incomplete or ambigously described,as seems here. Nowhere was it mentioned that there has to be a space between W and L.

Someone asked this as well, but wasn't responded.

I suppose in an earlier problem, in a similar situation, a whitespace actually devoided me from the correct answer. It wasn't mentioned there either. Its tough deciphering the output formats, and eventually ends up in hit and trial...is there a wiki or anything on that...

Did you see the sample I/O

admin @ 25 Nov 2009 05:52 PM

Did you see the sample I/O provided in the probelm?

who will be the winner for

gunjanbansal @ 27 Nov 2009 02:14 PM

who will be the winner for the foloowing case and how

2

10 100

100 10

 

Read the last sentence before

triplem @ 29 Nov 2009 04:09 PM

Read the last sentence before 'input' if you were asking what should happen in a tie. Of course, that case isn't a tie.

if it is not a tie then who

gunjanbansal @ 30 Nov 2009 10:18 AM

if it is not a tie then who should be winner ??

i cudnt c any other corner cases .

The winner is easily player

triplem @ 30 Nov 2009 01:00 PM

The winner is easily player 2. Read the problem statement again.

@Admins: thanks for fixing

jcomeau_ictx @ 1 Dec 2009 01:49 AM

@Admins: thanks for fixing the "successful submissions" database problem that existed on several test problem pages. Is it possible all the missing markup on the problem pages be likewise fixed? I'd like to know whether "1 Si 10000" means "1 is less than Si is less than 10000" or "is less than or equal to". Thank you -- jc

to those coders who, like me,

jcomeau_ictx @ 1 Dec 2009 05:38 AM

to those coders who, like me, keep getting "Wrong answer": pay particular attention to the tabular data in the problem statement appearing after the sentence "The total scores of both players, the leader and the lead after each round for this game is given below". Put a debugging statement into your code at the end of the loop, making sure your tally matches that, and you're golden.

This is fixed.

admin @ 1 Dec 2009 02:49 PM

This is fixed.

it is showing wrong answer in

anurag_aggarwal @ 3 Dec 2009 03:35 PM

it is showing wrong answer in my code but it gives correct answer in my compiler

i have also tried the

anurag_aggarwal @ 3 Dec 2009 03:40 PM

i have also tried the debugging statement to check whether the lead and leager at the end of each round it still gives correct answer in mine compiler

  I've tried so many cases

apoorvbirthare @ 13 Dec 2009 05:34 PM

 

I've tried so many cases and its working fine with my JVM

I donno why I m gettin wromg answrs here.

Can sm1 plz point out the prblm in my code...?

My problem id is 150616


for all those getting wrong

chang @ 13 Dec 2009 06:09 PM

for all those getting wrong answer...the only thing is to be checked is dat u keep on adding the scores of previous rounds before calculating the lead. :D

for all those getting wrong

chang @ 13 Dec 2009 06:10 PM

for all those getting wrong answer...the only thing is to be checked is dat u keep on adding the scores of previous rounds before calculating the lead. :D

umm i really dont think u

Anirudh_s @ 21 Dec 2009 08:57 PM

umm i really dont think u should do that

some weird behavior in

prm2612 @ 27 Dec 2009 12:27 PM

some weird behavior in execution times:

my submissions 154550 and 154558 are exactly same line by line... but even then there is a difference in execution times of both 4.52 and 4.67 respectively.

Admin, can you please explain the reason for such a behavior.

Please let me know the reason

bhanu.ashwani @ 29 Dec 2009 03:44 PM

Please let me know the reason of wrong answer in my submission.

The same problem everyone

triplem @ 30 Dec 2009 01:59 AM

The same problem everyone else has. You haven't read/understood the problem statement. Read it again.

coders who got wrong answere

dabbcomputers @ 17 Jan 2010 07:07 PM

coders who got wrong answere chk their code for input

2

1 2

80 42

and answere shuld be

1 37

not 1 38

the reson is defined in the statement read it carefully.........

@AMRITPAL thaks a lot, your

tsam910 @ 31 Jan 2010 02:42 AM

@AMRITPAL thaks a lot, your comment really helped :)

AMRITPAL i cant get what you

ashish24 @ 13 Feb 2010 01:52 PM

AMRITPAL i cant get what you want to say

because 80-42 = 38 how do you say it is 37

And which statement are you talking about.

The problem statement. It

triplem @ 13 Feb 2010 02:12 PM

The problem statement. It clearly defines the problem, despite the fact that so many people do not bother to read it correctly :)

@ashish read the test cases

dabbcomputers @ 18 Feb 2010 06:02 PM

@ashish read the test cases described in statements and u must got point

I'm reading in data in C++

Spidelytwang @ 5 Mar 2010 10:39 AM

I'm reading in data in C++ using

cin >> Si >> Ti;

and after testing values on my machine, the program outputs the correct answer in format using

cout << W << L;

However, upon submission it appear as though the answer is incorrect. I'm assuming that I've made a mistake in how I am reading the data in. Can anyone clear this up?

Do you really think it is

triplem @ 5 Mar 2010 11:30 AM

Do you really think it is more likely that cin >> Si >> Ti is wrong than the rest of your algorithm?

It's pretty obvious that line has no bugs in it.

I'm afraid the rest of your algorithm is completely wrong. Read the problem statement again; you haven't understood it at all.

Thank you for the reply. In

Spidelytwang @ 5 Mar 2010 11:51 AM

Thank you for the reply. In my program I have been using cout << W << ' ' << L; I forgot to mention that.

If I build an array of sample data as indicated above, my output matches that specified by the program exactly. I don't think this problem stems from a misunderstanding of the program, but rather how I am parsing the data.

The mistake is most

triplem @ 5 Mar 2010 12:38 PM

The mistake is most definitely in the understanding of the problem. Like I said, the lines to read + write input are very simple - if you had made a mistake there I think you would know it.

You are getting the correct answer for the sample input, but for the wrong reason. The problem statement clearly explains how the sample output is generated - compare that with what your code does.

Once all the rounds are over

codegambler @ 17 Mar 2010 12:38 AM

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.

this is the only line need to be taken care for solving this problem.

I've lost almost half an hour

Vareski @ 27 Apr 2010 02:46 PM

I've lost almost half an hour trying to figure out why i kept getting Wrong Answer, and reading all the comments.

I think the sample test case leads to misunderstandings, because letting the winner take the max lead at round one didn't led me (and i think a lot of other people) to understand what is the true logic of the problem.

I don't want to help too much posting corner test cases or giving explanations, but If you want to correctly solve the problem then carefully read this part and look at how the lead is calculated:

Consider the following score sheet for a game with 5 rounds:

Round Player 1 Player 2

1 140 82
2 89 134
3 90 110
4 112 106
5 88 90

The total scores of both players, the leader and the lead after each round for this game is given below:

Round Player 1 Player 2 Leader Lead

1 140 82 Player 1 58
2 229 216 Player 1 13
3 319 326 Player 2 7
4 431 432 Player 2 1
5 519 522 Player 2 3

P.S. Ties are formally possible but the victory is given to the first one who gets the same maxlead. (I'm not posting a test case right now because it will help too much)

In his version, at the end of

gunjanbansal @ 13 May 2010 02:10 PM

In his version, at the end of each round the leader and her "CURENT 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.

 

Here what is meant by current lead . If as amritpal pointed in example

"

2

1 2

80 42

and answere shuld be

1 37

not 1 38 "

then answer in the given example must be 1 71  ..

Sorry please ignore my last

gunjanbansal @ 13 May 2010 02:24 PM

Sorry please ignore my last comment , amritpal correctly pointed out the error in my interpretation , finaly got a correct answer :)

I am getting runtime

bharath.ase @ 21 May 2010 11:05 PM

I am getting runtime error......can someone tell me exactly how to get rid of it?

It should be pretty obvious.

triplem @ 22 May 2010 03:16 AM

It should be pretty obvious. Read the input section.

i have added the scores and

scorpio90 @ 1 Jun 2010 04:07 PM

i have added the scores and den calculated the lead and the winner accordingly...stil m getting wrong answer...please help

Please do not post code here

triplem @ 1 Jun 2010 04:38 PM

Please do not post code here (FAQ).

Why are you sorting your vectors with a method that uses chars, when they are ints?

@admin can u look at my

Bhoomit @ 10 Jun 2010 09:59 AM

@admin can u look at my solution why it is geting wrong ans, its working with guven test case on my local machine

@admin can u look at my

Bhoomit @ 10 Jun 2010 09:59 AM

@admin can u look at my solution why it is geting wrong ans, its working with guven test case on my local machine

Your code gives the wrong

triplem @ 10 Jun 2010 11:37 AM

Your code gives the wrong answer on almost every other test case. You haven't read the problem statement properly.

i completed running it in

rhitwik2010 @ 19 Jun 2010 04:21 PM

i completed running it in 0.03.but still my name is not shown in the list of successful submission

what is wrong with this

udit_sharma @ 19 Jun 2010 04:36 PM

what is wrong with this showing that wrong answer while i am getting correct answers on my pc.. :(

Do not post code here (FAQ).

triplem @ 20 Jun 2010 04:47 AM

Do not post code here (FAQ). You, like lots of other people, haven't read the problem statement. Read it again.

I've tested my code against

shwetanka_19 @ 20 Jun 2010 03:20 PM

I've tested my code against many inputs and every time i'm getting the correct answer.Still when i submit it says wrong answer. can anyone check my code and tell me in which case code will not work or what is wrong with the code.

import java.util.*;

public class Main

{

public static void main(String a[])

{

Scanner sc=new Scanner(System.in);

int n=Integer.valueOf(sc.nextLine());

String inp[]=new String[n];

for(int i=0;i<n;i++)

inp[i]=sc.nextLine();

int win[]=new int[2];

for(int i=0;i<n;i++)

{

StringTokenizer st=new StringTokenizer(inp[i]," ");

String p1=(String)st.nextToken();

String p2=(String)st.nextToken();

int ret[]=checkLead(Integer.valueOf(p1),Integer.valueOf(p2));

if(ret[1]>win[1])

{

win[0]=ret[0];

win[1]=ret[1];

}

}

System.out.println("n"+win[0]+" "+win[1]);

}

public static int[] checkLead(int n1,int n2)

{

int tem[]=new int[2];

if(n1>n2)

{

tem[0]=1;

tem[1]=n1-n2;

}

else

{

tem[0]=2;

tem[1]=n2-n1;

}

return tem;

}

}

^ Read the comment directly

f03nix @ 22 Jun 2010 07:51 AM

^ Read the comment directly above your post, and in future avoid asking queries already been answered (unless you require further clarification on a specific part of it).

Sorry for posting the code

shwetanka_19 @ 22 Jun 2010 11:37 PM

Sorry for posting the code here....  I didn't pay attention to that code is not allowed here...

and I think i didn't read the sample input properly...

Now i got it where i'm wrong..

thanks.

I have a query .... for my

shwetanka_19 @ 22 Jun 2010 11:57 PM

I have a query .... for my solution it show 4.59 sec. but time limit is 1 sec so why don't it give time limit exceeded in the result?

Again, you should give FAQ

f03nix @ 23 Jun 2010 12:10 AM

Again, you should give FAQ another reading. Codechef might test your code multiple times with different input files. If your code gives the correct answer within the time limit for each input file, the execution time displayed is the total of the time spent for each test case.

So, if it tests your program on (say) 5 input files ... and your code takes .9 sec for each (< 1 sec). TIme displayed will be 4.5 sec.

@admin could u pls show the

harit @ 24 Jun 2010 11:58 PM

@admin could u pls show the input for which my program is being tested.....

never ever rely only on the

aditya_gaur @ 30 Jun 2010 01:58 PM

never ever rely only on the sample input output data ...read the problem statement carefully.....:D

For all : 1. I rectified the

akshay.live @ 5 Jul 2010 10:11 AM

For all :

1. I rectified the error.. Please keep a track of TOTAL difference in scores.. Also the test output is CORRECT. See the 1st table and 2nd table again..

2. For all C++ users : Leave a space between w and l.. i.e; cout<<w<<" "<<l;

 

-Akshay

@admin could u please tell

anubhav.7nov @ 16 Jul 2010 04:01 PM

@admin could u please tell wats wrong with my code no.-288831

when i submit it says wrong anwer..

That's because you, like most

triplem @ 16 Jul 2010 04:16 PM

That's because you, like most people, aren't calculating what the problem statement tells you to. Read it again.

@admin can u please clarify

anubhav.7nov @ 16 Jul 2010 09:23 PM

@admin

can u please clarify what im not calculating.

i still not getting it..

The problem statement has a

triplem @ 17 Jul 2010 03:18 AM

The problem statement has a very detailed explanation of the sample input, and calculates the values 58, 13, 7, 1, and 3. Where do you calculate those values?

@admin, plz kindly prepare a

vidura @ 3 Aug 2010 10:52 PM

@admin,

plz kindly prepare a way to see the test cases. It will be a great help for all of us!

can anyone help me to

aabidhasan @ 4 Aug 2010 10:59 PM

can anyone help me to understand why it is showing wrong answer??? I am not getting any mistake. please help.

 

#include<stdio.h>

 

int player,lead1,newlead1,lead2,newlead2,n,m,number;

 

int main(){

int i,j;

lead1=lead2=0;

//freopen("input.txt","r",stdin);

scanf("%d",&number);

for(i=0; i<number; i++){

scanf("%d %d",&n,&m);

if(n>=m){

newlead1=n-m;

if(newlead1>lead1){

lead1=newlead1;

}

}

else {

newlead2=m-n;

if(newlead2>lead2){

lead2=newlead2;

}

}

}

if(lead1>lead2)printf("1 %dn",lead1);

else printf("2 %dn",lead2);

return 0;

}

Read the explanation of how

triplem @ 5 Aug 2010 02:44 AM

Read the explanation of how the sample output is calculated.

is the question jus abt ...

rahulagarwal90 @ 5 Aug 2010 07:50 PM

is the question jus abt ... calculating the max lead from all the rounds ...and the leader who got the lead.

@sysadmin ...can u tell me

rahulagarwal90 @ 5 Aug 2010 07:53 PM

@sysadmin ...can u tell me wat is the problem with my sol.

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

Same as everyone else. The

triplem @ 6 Aug 2010 03:01 AM

Same as everyone else. The input provides a clear example of what to do and how to do it, but you are doing something different.

Hello Admin I have tried as

Milan_Singh @ 14 Aug 2010 02:30 PM

Hello Admin

I have tried as many as possible test cases I could and getting right answers for all of them. I have already gone through the queries written above and made every possible change but still it is giving wrong answer.

Can you please help me out with this? My program code is 307859! Just let me know where am I making a major flaw as for which I am shown a "WRONG ANSWER" every time:P

Try this test case: 21 01 0

triplem @ 16 Aug 2010 10:48 AM

Try this test case:

2
1 0
1 0

plz tell why my answer is

garg_ayush @ 23 Aug 2010 12:08 AM

plz tell why my answer is wrong?

Same reason everyone else's

triplem @ 23 Aug 2010 10:31 AM

Same reason everyone else's is. Try reading the problem statement again (or the comments..)

i have made several changes

garg_ayush @ 23 Aug 2010 11:35 PM

i have made several changes but still not working.

plz help.

my program code is 313607.

urgent

http://www.codechef.com/views

notyabhi @ 23 Aug 2010 11:49 PM

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

 

is there any error?? answer is coming wrong everytime when I am submitting the problem. But I am trying all d possible test cases and getting the right answer

i too was getting wrong

thechamp @ 28 Aug 2010 10:32 PM

i too was getting wrong answer guys, spending 1 hour gazing at the problem statement + 5 minute "concentration" on table 1 & 2 solved the problem. all those who could not solve yet, guys your algo is perfect but you miss something in problem statement.. re-read TABLES :)

dear Admin, i have submitted

nirajkant @ 13 Sep 2010 05:02 PM

dear Admin,

i have submitted problem for this in c++ it got accepted.

but i have a doubt why my same code show runtime error when try submitting in c .

ya its same code(no compile error).

 

 

c++ --> http://www.codechef.com/viewsolution/331574

c    ---->http://www.codechef.com/viewsolution/331576

 

pls suggest what might be the reasons .

Because your main method

triplem @ 14 Sep 2010 02:50 AM

Because your main method doesn't return 0.

thnks Stephen its now k now i

nirajkant @ 18 Sep 2010 03:52 PM

thnks Stephen its now k now i understand.

hey my program is working

sachin_56 @ 26 Sep 2010 06:42 AM

hey my program is working fine on my comp....but when i submit its givin runtime error pls help me...

thanks the_champ Shame !

default1130 @ 6 Oct 2010 11:18 PM

thanks the_champ

Shame ! could not figure that out myself

@Stephen Merriman What's the

knightyau @ 20 Oct 2010 07:13 AM
@Stephen Merriman

What's the output for this test case?

4

1 0

0 1

0 1

1 0

 

is it

1 1

or

2 1

 

thanks

 

@Admin http://www.codechef.co

knightyau @ 20 Oct 2010 07:17 AM

@Admin

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

can help me check whats the prob?

i hv been trying all d corner-cases but still get WA.

please gv me some hints if u have checked my solution.thanks

@Admin owh i get it sorry for

knightyau @ 20 Oct 2010 07:43 AM

@Admin

owh i get it sorry for troubling. thanks :)!

everytym i try to submit a

sunny_days @ 28 Oct 2010 12:45 PM

everytym i try to submit a solution i get an error stating that solutions to this problem cannot be submitted...

wats d problem??

ashamed to say, i needed two

shaon_255 @ 9 Nov 2010 07:51 PM

ashamed to say, i needed two attempts.

for those getting wrong answer, read the problem thoroughly, paying attention to the size of variables needed. and check ur codes. its rly as simple as it seems.

i m getting the correct

achiever_mohit @ 16 Dec 2010 12:08 AM

i m getting the correct output on my system..bt dont no why its getting wrong here ....plz help

You, like almost everyone

triplem @ 16 Dec 2010 02:21 AM

You, like almost everyone else in this thread, haven't read the problem statement. Read it again.

Seems like all the coders

darkmonk @ 18 Dec 2010 10:27 PM

Seems like all the coders around the world are the same hehe :P

/*the lead gameinput:scores

ben_hilfy @ 20 Dec 2010 09:04 PM

/*the lead game
input:scores of two players in different rounds
output:winner and respective lead
*/

#include<cstdio>
#include<cmath>

int main()
{
//freopen("input.txt","r",stdin);
int n;
int lead=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int sum1=0,sum2=0;
int score1,score2;
scanf("%d%d",&score1,&score2);
sum1=sum1+score1;
sum2=sum2+score2;
if(fabs(sum1-sum2)>fabs(lead))
{
lead=sum1-sum2;
}
}
if(lead > 0)
{
printf("1 %d",lead);
}
else
{
printf("2 %d",(-lead));
}
return 0;
}

pls tell me what is d problem ith my solution

Hey guys idk why im getting

DevilsEye @ 24 Dec 2010 01:51 PM

Hey guys idk why im getting run time error my prog is correct

for the test case :

Input :

2

1 0

1 0

Output :

 

1 2

--------------------

another test case

--------------------

input :

2

1 2

80 42

output :

1 37

 

but still is saying runtime error..

is working fine on my machine..

here is the code

DevilsEye @ 24 Dec 2010 01:54 PM

here is the code :

 

#include<stdio.h>

int main()

{

int round,flag;

int x,y;

int p1=0,p2=0;

int lead=-1;

scanf("%d",&round);

while(round>0)

{

scanf("%d %d",&x,&y);

p1=p1+x;

p2=p2+y;

if(p1>p2)

{

if((p1-p2)>lead)

{

lead=p1-p2;

flag=1;

}

}

else if(p2>p1)

{

if((p2-p1)>lead)

{

lead=p2-p1;

flag=2;

}

}

round--;

}

printf("%d %d",flag,lead);

}

Please read the FAQ.

triplem @ 24 Dec 2010 04:04 PM

Please read the FAQ.

@Admin: My solution is

rajneesh2k10 @ 25 Dec 2010 10:49 AM

@Admin:

My solution is working fine with the test case provided and I think it'll work well with all others too. But don't know how I am getting a wrong answer. Please provide me with the test case on which my solution is failing. I have crosschecked it thoroughly. You can have a look at my solution here: http://www.codechef.com/viewsolution/406578

Can someone tell me what's

guru1306 @ 25 Dec 2010 12:48 PM

Can someone tell me what's wrong with my code?

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

Earlier one was a wrong

guru1306 @ 25 Dec 2010 02:00 PM

Earlier one was a wrong code.But I don't know why this one is failing.

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

 

 

 

 

 

int nog,*s1,*t1; int

gaya3k @ 26 Dec 2010 02:05 AM

int nog,*s1,*t1;
int l1,max=0,w=1,flag;
cin>>nog;
s1=new int[nog];
t1=new int[nog];
for(int i=0;i<nog;i++)
cin>>s1[i]>>t1[i];
for(int j=0;j<nog;j++)
{
if(s1[j]>t1[j])
{
l1=s1[j]-t1[j];
flag=1;
}
else
{
l1=t1[j]-s1[j];
flag=0;
}
if(max<l1)
{
max=l1;
(flag)? w=1 : w=2;
}
}
cout<<w<<"t"<<max<<endl;

this is my code and it is working for the sample i/p given here but i get wrong answer could anyone please help me with what is wrong in it?

The compiler I use is g++

gaya3k @ 26 Dec 2010 02:15 AM

The compiler I use is g++ 4.4.3 and the latest version available here is 4.3.2 does that have any thing to do with the solution i submit

Because for two problems the solution i have submitted was given wrong answer even though the logic was same as many of the successful solutions submitted. Any help please?

I'm afraid your solution is

triplem @ 26 Dec 2010 04:14 AM

I'm afraid your solution is plain wrong. Read the problem statement again.

@Admin: My solution is

rajneesh2k10 @ 26 Dec 2010 12:44 PM

@Admin:

My solution is working fine with the test case provided and I think it'll work well with all others too. But don't know how I am getting a wrong answer. Please provide me with the test case on which my solution is failing. I have crosschecked it thoroughly. You can have a look at my solution here: http://www.codechef.com/viewsolution/406578

It'll be of great help if you figure out the problem from my code!

Same comment as above.

triplem @ 26 Dec 2010 12:51 PM

Same comment as above.

@Stephen: Thank you so much

rajneesh2k10 @ 26 Dec 2010 07:59 PM

@Stephen: Thank you so much for your prompt reply! But idea in my mind still remains the same. If I have read the problem statement correctly: Winner is the player who has made the biggest difference in the scores in any of the rounds! That's what I have coded for.

My algorithm goes as:

1. For the first input determine the winner of the game and her lead.

2. For all the next inputs, first determine the lead scored by the players, if this lead is more than the previosuly scored lead then store the new lead and determine the new player who is the winner of the game else don't do anything.

3. Finally print the output.

Hope its fine. If possible give me the test case on which my input fails.

Thank you once again!

The problem statement has a

triplem @ 27 Dec 2010 02:13 AM

The problem statement has a very detailed explanation of the sample input. One of the numbers it calculates is 13. Where do you calculate the number 13 in your program?

@Gayathri,   Why are you

guru1306 @ 27 Dec 2010 11:15 AM

@Gayathri,

 

Why are you printing a "t" in between the two variables in the output?

 

 

Guru

@Admin Can you please let me

guru1306 @ 27 Dec 2010 11:23 AM

@Admin

Can you please let me know for which testcase my code is failing

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

 

You too should read the

triplem @ 27 Dec 2010 01:17 PM

You too should read the problem statement or my last few comments.

@stephen: If you look at the

rajneesh2k10 @ 27 Dec 2010 02:50 PM

@stephen: If you look at the second statement inside the while loop, there I have calculated the difference between the next scores of the plapyers i.e. 13 is also calculated there but since 13 is no greater than 58 so the lead is not updated and neither the winner is updated. I ran my code step by step and checkd the values of the variables too, there I got 13. Please look into it again.

It'll be of much help if you could give me a test case which cause my code to fail! Thank you once again!!

No, you do not. Add a printf

triplem @ 27 Dec 2010 03:41 PM

No, you do not. Add a printf statement and tell me if it says 13 or not when you use the sample input.

@stephen: I put a printf

rajneesh2k10 @ 28 Dec 2010 01:41 PM
@stephen: I put a printf statement after every line inside the loop and watched the output carefully. The output was as expected. This statement calculates the difference in the scores in every round inside the loop: temp=(s>t)?(s-t):(t-s); I can't understand why you say that I won't get a 13. I am getting it because of above statement. Please give me a sample input which cause my code to fail. Sorry! this time our discussion is going so longer and longer.... Please help me. Thanks.

I'm afraid you don't seem to

triplem @ 29 Dec 2010 02:08 AM

I'm afraid you don't seem to have done what you said you did at all..

I added printf("%d\n",lead) before your while (--n) loop, and printf("%d\n",temp) after you calculate temp. If you run that on the sample input provided at the bottom/top of the problem, you print out:

58
45
20
6
2
1 58

I don't know how you get anything different.

@Stephen: First, I am sorry

rajneesh2k10 @ 29 Dec 2010 08:32 AM

@Stephen: First, I am sorry for all the foolishness I did. I should have payed attention to the first comment. :)

Second, I had added printf to all the places and had watched the output as I said (Why at all would I lie?) but actually I was running my code on the wrong inputs. I thought those are two different set on inputs. I never figured out that the scores are cumulatively added (neither its mentioned in the problem statement but its clear from the example). I thought those are two different set of inputs. So, lots of confusion!! Finally I read the problem statement and its all done.

Thank you so much for your patience. Love you. Muahhh. You deserved this.  :) :) :)

You should have just mentioned one line- The scores are cumulative. :)

I could have said the scores

triplem @ 29 Dec 2010 09:37 AM

I could have said the scores were cumulative, but then you wouldn't have learnt that you should read the problem statement carefully :P

(Besides, that has already been mentioned heaps of times in the comments too, so now you know to read them too ;))

@Stephen: Yeah!! You are

rajneesh2k10 @ 29 Dec 2010 10:49 AM

@Stephen: Yeah!! You are right. But I think one should be able to solve the problem without reading the comments. These are if a help is needed. :)
Anyways, Great Work. I learnt some lessons from here.

#include<stdio.h> int

eagleye @ 3 Jan 2011 11:45 PM

#include<stdio.h>

int main()

{

int x,n=0,m=0,i,a,b,lead=0,leader=0;

scanf("%d",&x);

for(i=0;i<x;i++)

{

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

if(a>b)

{m=a-b;

lead=1;

}

else

{m=b-a;

lead=2;

}

if(m>n)

{n=m;

leader=lead;}

}

printf("%d %d",leader,n);

return 0;

}

 

i think it is the shortest code nd its working finely in my gcc compiler.but here on codechef compiler it is shown as wrong answer.

admin plz plz plz help

admin or any1 plz help yar.i

eagleye @ 4 Jan 2011 12:50 AM
admin or any1 plz help yar.i have done some corrections yet i it showing wrong answer

Read the explanation of the

triplem @ 4 Jan 2011 01:42 AM

Read the explanation of the sample input. You are solving the wrong problem.

@stephen:sir can u explain

eagleye @ 4 Jan 2011 11:29 AM

@stephen:sir can u explain plz what the sample output says.i have done same thing nd i have checked many inputs nd it is giving right answer every time :(

Like I said to the person

triplem @ 4 Jan 2011 11:36 AM

Like I said to the person posting several comments before you - the sample input is explained in detail in the problem statement. If you aren't calculating the values 58, 13, 7, 1 and 3 for that input, then you are doing something wrong.

yes m calculating the values

eagleye @ 4 Jan 2011 11:41 AM

yes m calculating the values sir bt m updating the value of variable every time if the value occurs is greater than first value.

are you saying that i have to store 58,13,7,1 in different variables or array

Hello, Can anyone please tell

code_learner @ 18 Jan 2011 07:53 PM

Hello,

Can anyone please tell me whats wrong with my solution : http://www.codechef.com/viewsolution/425844

Its giving "Wrong Answer" . I tried the test case given in question. My output was correct. Why is it showing Wrong Answer?

@Jason: Please read the above

rajneesh2k10 @ 18 Jan 2011 11:10 PM

@Jason:

Please read the above comments. Your answer is there only. :)

@ Rajneesh, If you are

code_learner @ 19 Jan 2011 12:16 AM

@ Rajneesh,

If you are doubting that I might not be updating score of each player after each round, I am doing that now, please see the code here : http://pastebin.com/dXMUMkur

I checked output at after each loop using printf, it works fine that is I get 58, 13, 7 , 1 ,3. Whats missing ? Please help.

You have a problem related to

triplem @ 19 Jan 2011 01:29 AM

You have a problem related to temp1 and temp2.

@Jason: Stephen is right! A

rajneesh2k10 @ 19 Jan 2011 08:10 AM

@Jason:

Stephen is right! A very small mistake! :)

@admin: I am getting same

akash_d_learner @ 27 Jan 2011 01:04 AM

@admin: I am getting same runtime error for every different solution i am posting on code chef. Even thought there is no division by zero in the program and i ve used only 6 int variables in my program that accounts only 24bytes and taking cost of other class memory it should not go more than 100bytes.

my submission:

The lead game: http://www.codechef.com/viewsolution/435605

Paying Up: http://www.codechef.com/viewsolution/435048

Sum of triangle : http://www.codechef.com/viewsolution/434420

Same error pops up into my every submission. Please help me.

That's because you're making

triplem @ 27 Jan 2011 01:30 AM

That's because you're making the same mistake every time. Have you tried testing your code, at least on the sample inputs? If you do so the reason for the error will be obvious - the input often consists of numbers on the same line; whereas you assume every number on the input is on a new line.

@admin : Got the error. Thank

akash_d_learner @ 27 Jan 2011 01:32 AM

@admin : Got the error. Thank you..

@Stephen: My Lead game is

akash_d_learner @ 27 Jan 2011 03:18 AM

@Stephen: My Lead game is showing Wrong answer now. Can you just give hint abt the prob. I ve now tested the sample input. Rest of my solution are accepted.

Url: http://www.codechef.com/

akash_d_learner @ 27 Jan 2011 03:20 AM

Url: http://www.codechef.com/viewsolution/435652

You're making the same

triplem @ 27 Jan 2011 03:54 AM

You're making the same mistake as everyone else. The sample input is explained in the problem. Make sure you are calculating the same values as it does (you aren't).

@stephen- sir , i have sent

arpitg1991 @ 29 Jan 2011 09:25 PM

@stephen- sir , i have sent you a PM, please check.

thank you.

the solution i have submitted

abhishekgoel7 @ 21 Feb 2011 07:39 PM

the solution i have submitted is running well in my computer & giving right output.

but here it shows dat it is giving wrong answer,,,,.

Please check my code, it is

kapilagarwal @ 13 May 2011 12:58 PM

Please check my code, it is giving the right answer for the various cases I have tested but here it gives wrong answer. The id is 547999.

done :) must read the problem

deftar @ 25 May 2011 03:18 AM
done :) must read the problem statement more carefully next time..

#include int main() { int

harshith123456 @ 9 Jun 2011 11:29 AM
#include int main() { int p1[10000],p2[10000],ld[10000],lr[10000],i,n,max; scanf("%d",&n); for(i=1;i<=n;++i) { scanf("%d%d",&p1[i],&p2[i]); ld[i]=p1[i]-p2[i]; if(ld[i]>0) lr[i]=1; else if(ld[i]<0) { lr[i]=2; ld[i]=-1*ld[i]; } } max=ld[1]; for(i=2;i<=n;++i) { if(ld[i]>max) max=ld[i]; } for(i=1;i<=n;++i) { if(max==ld[i]) { printf("%d %d",lr[i],ld[i]); break; } } return 0; } can anyone tell why this is generating a wrong answer

please check my solution ,

harshit_sharan @ 10 Jun 2011 03:01 AM
please check my solution , its giving wrong answer... i have considered the flaw that were there in many codes becoz of carelessly reading the problem... http://www.codechef.com/viewsolution/569950

Requires more of reading

prakash1529 @ 17 Jun 2011 08:02 AM
Requires more of reading skills than solving skills. Nice trap code chef :) Analyse the data given in both the tables

i've learnt alot from this

kevinfrankly @ 7 Jul 2011 10:06 PM
i've learnt alot from this test !!!! READ CAREFULLY damn this test is tricky, have wasted about 5 hours for debuggin' my crap code

@Admin Could you please give

hollgam @ 12 Jul 2011 02:18 AM
@Admin Could you please give me a small pointer on what is wrong with this solution: http://www.codechef.com/viewsolution/598523 I've read all the comments and like many others had to change the logic but I am still getting the wrong answer.

can smebody help me??? its

abhinavtyagi @ 21 Jul 2011 01:35 AM
can smebody help me??? its showin RTE but i cant understand...runs fine on my system....sol no602287..pls help..

Problem says "Once all the

playnoob @ 6 Aug 2011 05:46 PM
Problem says "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"

why the compiler of code chef

saurabhzx @ 9 Aug 2011 03:16 PM
why the compiler of code chef consider it as a wrong answer as it is successfully working in turboc 3.... # #include # int main(void) # { # int *a,*b,n,*on,*of,big,aig,i; # printf("enter the number of rounds"); # scanf("%d",&n); # a=(int*)calloc(n,sizeof(int)); # b=(int*)calloc(n,sizeof(int)); # # on=(int*)calloc(n,sizeof(int)); # # of=(int*)calloc(n,sizeof(int)); # for(i=0;ib[i]) # { # on[i]=a[i]-b[i]; # # } # else # { # of[i]=b[i]-a[i]; # # } # } # aig=on[0]; # for(i=0;ion[0]) # { # aig=on[i]; # } # } # big=of[0]; # for(i=0;iof[0]) # { # big=of[i]; # } # } # if(big>aig) # { # printf("player 2 wins"); # } # else if(big

reading skills are quite a

nitin_surana @ 25 Aug 2011 02:56 AM
reading skills are quite a much tested here...wasted about 2 hours debugging my erraneous code but finally.

can any one help me in this

aring @ 27 Aug 2011 09:55 AM
can any one help me in this and it is showing wrong ans i m not getting mistake plz help. #include int main() { int n,p1s,p2s,c1=0,c2=0,ms1=0,ms2=0,i=1,j=2; scanf("%d",&n); while(n>0) { scanf("%dt%d",&p1s,&p2s); if(p1s>p2s) { c1++; if(ms1<(p1s-p2s)) { ms1=p1s-p2s; } } else { c2++; if(ms2<(p2s-p1s)) { ms2=p2s-p1s; } } n--; } if(c1>c2) { printf("%d%dn",i,ms1); } else { printf("%d%dn",j,ms2); } return 0; }

#include int max(int

raja_utkarsh @ 30 Aug 2011 01:41 AM
#include int max(int x[100000],int p) { int i; int max=x[0]; for(i=1;i<=p-1;i++) { if(x[i]>max) max=x[i]; } return(max); } int main() { int i=0,j=0,q,k,l,s,m,n; int a[600]={0},b[600]={0}; scanf("%d",&n); for(s=0;s<=n-1;s++) { scanf("%d%d",&m,&l); if(m>l) a[s]=m-l; else b[s]=l-m; } i=max(a,n); j=max(b,n); if(i>j) printf("1 %d",i); else printf("2 %d",j); return 0; } code is right in dev c++ but giving runtime error in this can anyone point my mistake plz...

#include int max(int

raja_utkarsh @ 30 Aug 2011 01:42 AM
#include int max(int x[100000],int p) { int i; int max=x[0]; for(i=1;i<=p-1;i++) { if(x[i]>max) max=x[i]; } return(max); } int main() { int i=0,j=0,q,k,l,s,m,n; int a[600]={0},b[600]={0}; scanf("%d",&n); for(s=0;s<=n-1;s++) { scanf("%d%d",&m,&l); if(m>l) a[s]=m-l; else b[s]=l-m; } i=max(a,n); j=max(b,n); if(i>j) printf("1 %d",i); else printf("2 %d",j); return 0; } code is right in dev c++ but giving runtime error in this can anyone point my mistake plz...

@raja_utkarsh: you are using

vijay91 @ 30 Aug 2011 04:56 PM
@raja_utkarsh: you are using array of 600 which is not capable of holding N numbers...see the constraints on N (N <= 10000)

This problem has issues.

abhijeet080808 @ 1 Sep 2011 01:44 PM
This problem has issues. The solution that does not meet the example given got passed, while the correct solution gives "wrong answer". Basically, calculation the total lead over all rounds summed together is what is accepted as correct but it should have been the largest lead per round. Simply put- 2 1 0 1 0 This is accepted as correct - 1 2 But as per description, should have been - 1 1

Dear...Admin..this is my

abir1abir28 @ 4 Sep 2011 12:23 AM
Dear...Admin..this is my first comment on this platform.I don't clearly understand this problem..Is here total rounds are limited by "1

Here is my code that took

tandemcoder @ 27 Sep 2011 11:14 PM
Here is my code that took 0.08 secs to run: #include #include int main() { int score[3]={0},n,flag=0,max=0; scanf("%d",&n); while(n--) { scanf("%d",&score[0]); score[1]+=score[0]; scanf("%d",&score[0]); score[2]+=score[0]; if((abs(score[2]-score[1]))>max) { max=abs(score[2]-score[1]); if(score[1]>score[2]) flag=1; else flag=2; } } printf("%d %d",flag,max); } _________ Here is another guy's successful submission which took 0.05 secs to run. I WANT TO KNOW WHY ?? #include int main() { int n, first[10000], second[10000]; int c, winner = 0, l, p, x, w; int sum1 = 0, sum2 = 0, temp; scanf("%d",&n); for(c=0;csecond[0]) { p = first[0]-second[0]; w = 1; } else { p = second[0]-first[0]; w = 2; } l = p; for(c=0;csum2) { x = sum1 - sum2; if(x > p) { p = l = x; w = 1; } //printf("lead = %d winner = %dn",sum1-sum2,w); } else { x = sum2-sum1; if(x > p) { p = l = x; w = 2; } //printf("lead = %d winner = %dn",sum2-sum1,w); } } printf("%d %dn", w, l); return 0; } _____

what's wrong,plz

s1aurabhpal_7 @ 3 Oct 2011 02:43 PM
what's wrong,plz help.. [code] #include int main() { int N;scanf("%d",&N);int lead=0;int winner; while(N--) { int a,b;scanf("%d%d",&a,&b); int max = (a>b)?a:b; if(lead<2*max-a-b) { if(max==a)winner=1;else winner =2; } lead = (lead>2*max-a-b)?lead:2*max-a-b; } printf("%d %d",winner,lead); return 0; } [/code]

#include #include int

maks7251 @ 7 Oct 2011 12:55 PM
#include #include int main() { int i,j,lead=0,diff,playr; scanf("%d",&i); //number of rounds int a[i],b[i]; for(j=0;jb[j]) { diff=a[j]-b[j]; if(diff>lead) {lead=diff; playr=1; } } else { diff=b[j]-a[j]; if(diff>lead) {lead=diff; playr=2; } } } printf("%dt%d",playr,lead); return 0; } it says wrong answer...i cant understand what is wrong in it....pls help

we can attach stdlib.h or not

discoveranuj @ 16 Oct 2011 11:57 PM
we can attach stdlib.h or not

in my code i m using

discoveranuj @ 17 Oct 2011 12:27 AM
in my code i m using malloc..i m geeting wrong answer bcoz f this

@admin or any1 plz plz help

libracious @ 20 Nov 2011 11:00 PM
@admin or any1 plz plz help me http://www.codechef.com/viewsolution/736453 what is the problem with my code

My code is running properly

snigdhatalks @ 15 Dec 2011 02:34 AM
My code is running properly on notepad++,but here it shows Runtime Error.I'm unable to find out where exactly the problem is..please do help http://www.codechef.com/viewsolution/757277

My code is running properly

snigdhatalks @ 15 Dec 2011 03:00 AM
My code is running properly on devC++,but here it shows wrong answer.I've put different numbers and tried but can't get the error..please help http://www.codechef.com/viewsolution/757295

WINNING IS BASED ON TOTAL

ryker1990 @ 1 Jan 2012 11:58 AM
WINNING IS BASED ON TOTAL SCORE AND LEAD IS CUMULATIVE....THATS ALL!

i am getting the correct

lalit.sirsikar @ 8 Jan 2012 01:52 AM
i am getting the correct answer on my pc but it shows run time error here, what might be the problem. plz. help me with this.

Link for my solutions:

lalit.sirsikar @ 8 Jan 2012 01:54 AM
Link for my solutions: http://www.codechef.com/status/TLG,lalit.sirsikar

what the output should be

saurabh08 @ 11 Jan 2012 03:33 AM
what the output should be if....??? input: 2 10 9 9 10 output:??

The logic they use to check

tarun135 @ 26 Jan 2012 06:24 PM
The logic they use to check our ans is absolutely wrong..

My code is running properly

gahuja91 @ 26 Jan 2012 08:32 PM
My code is running properly on my PC but it shows runtime error here. Is the error occurring because i used command-line arguments. Plz help..

Description is strange.

feddya @ 21 Feb 2012 08:28 PM
Description is strange. Looking at it I made a program substracting each round scores to get best lead (229 - 216, 339 - 326, 431 - 432 etc). But it is wrong. Answers were accepted only after I changed comparison of total scores starting from the first and until current round (229 - 216, (229+319)-(216+326), (229+319+431)-(216+326+432) )

How is my code

hjain12345 @ 21 Mar 2012 11:02 AM
How is my code wrong??? #include int main() { int n,l=-1,w,temp,i; scanf("%d",&n); int arr1[10000],arr2[10000]; for(i=0;i0) { if(l

#include int main() { int

hjain12345 @ 21 Mar 2012 11:04 AM
#include int main() { int n,l=-1,w,temp,i; scanf("%d",&n); int arr1[10000],arr2[10000]; for(i=0;i0) { if(l

can u tell me for which test

hjain12345 @ 21 Mar 2012 10:53 PM
can u tell me for which test case my answer is wrong?????? because i am not able to find fault in my code...

u need to add previous round

jankur323 @ 27 Mar 2012 12:26 AM
u need to add previous round scores to current round score then u'll get correct answer.............

please check this

ujjwal12 @ 29 Mar 2012 10:31 PM
please check this solution..http://www.codechef.com/viewsolution/932892

@ujjwal In your code there is

tussharsingh13 @ 30 Mar 2012 04:49 PM
@ujjwal In your code there is no mechanism to sum up the scores Here the lead is the difference of the cumulative scores of all the previous rounds...:) :)

Can anybody please give the

neerajk @ 7 Apr 2012 08:52 PM
Can anybody please give the scenario when this solution will fail. Please http://www.codechef.com/viewsolution/965777

Anyone please please help

chetanspy007 @ 22 Apr 2012 05:26 PM
Anyone please please help me....... this is driving me nuts........ All it says is that "Runtime Error" And when u know that ua code is right, it pretty pisses u off...... So, lemme put my code here, and can anyone tell me what the mistake is please - #include void input(int *a,int *b,int ); void Check(int *,int *, int); main() { int n; scanf("%d",&n); int a[1000],b[1000]; input(a,b,n); Check(a,b,n); return 0; } void input(int *a, int *b,int n) { int i; for(i=0;i

I think that the main

wtq4er @ 3 May 2012 07:37 PM
I think that the main misunderstanding about this problem is in calculation the lead at the end of each round. look attentively at exmlpe. Lead is the difference between the SUMS of players' scores, but not the difference between scores at the end of the round.

Please tell me the problem

sinha2011 @ 4 May 2012 01:55 AM
Please tell me the problem with this code : http://www.codechef.com/viewsolution/1009971

int main() { int

helloworld001 @ 16 May 2012 04:23 PM
int main() { int n,i,w,l=0,k; cin>>n; int a[n],b[n]; for(i=0;i>a[i]>>b[i]; for(i=0;ib[i]) { k=a[i]-b[i]; if(l

@admin i think you shud make

mjnovice @ 23 May 2012 12:07 PM
@admin i think you shud make changes for the problem statement...as in the lead which is talked about is the cumulative lead(which works with the program) while what is demonstrated is the lead for the individua games....please see to this as soonest

"The Manager of Siruseri

akhilhandoo @ 23 May 2012 07:16 PM
"The Manager of Siruseri Sports Club decided to add his own twist to the game by changing the rules for determining the winner. In his version, 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." The problem statement is misleading. You actually look for cumulative lead. This is evident from the accepted solutions that i checked. The problem statement does not mention this at all. This should be embarrassing for you guys.

@akhilnandoo i support you.

mjnovice @ 23 May 2012 07:19 PM
@akhilnandoo i support you. the admins please see to this... soonest

Tricky question. Users who

nicepeeyush @ 25 May 2012 09:36 AM
Tricky question. Users who are getting wrong answer, read the statement carefully again...;)

@peeyush but the example

mjnovice @ 26 May 2012 08:44 AM
@peeyush but the example shown corresponds to the lead of the game; not the cumulative lead as has been asked and which works.......

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com