The Lead GameProblem code: TLG |
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 |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
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.

Fetching successful submissions

i dunno why every time i am getting the wrong answer...its working fine with the given input above...
Try some other inputs then :)
I'm getting the same problem, and I have tried other inputs and got no problems from them either...
Well, instead of trying random test cases, you should try finding corner-cases and test your code on those.
isnt the question is to find the maximum difference of scores among all rounds ? is der more to it ?
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.
You just have to output the two integers as specified in the statement.
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?
@admins hv a look at test data something is fishy here
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
The code is run against
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
Sorry, first player gets i
You are not taking input in
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
The example given in the
The example given in the problem statement demonstrates this clearly.
Does the o/p must contain a
i have given many inputs-all
Please don't post code here.
Please don't post code here.
As for the actual problem
Got Wrong Answer !!! not
thanks stephen...
can anyone tell what can b
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
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
@admin: Please give some tough corner test cases to try out ...
My code is 90719. I am not
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
isn't the output given in the example wrong??
Example
Input:
Output:
shouldn't the output be
1 140
??
my programme is working fine
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
@Sudeep - no, the example is correct, and there is a full explanation in the problem statement.
@Ankit This will be fixed
@Ankit This will be fixed ASAP
i am getting NZEC runtime
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,
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
doesnt 'throws IOException'
doesnt 'throws IOException' catch all exceptions?
does it give different
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
any recommendations for
do wrapper classes give
i jus checked my code on my
@Rakshith You need to exit
can i use parseInt directly
whats the problem with the
Please read the FAQ and the
This must be a deceptive
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
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
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
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
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
leave it
o_0
@admin, timit limit is for
@admin,
timit limit is for processing or both printing and processing(generally not specific to this problem)
Both printing and processing.
Both printing and processing.
those getting WA do note that
those getting WA do note that in each round the previous scores are added
Hey can the admin tell what
hey what happens if both get
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
Read the last sentence that comes before 'Input'.
i got result in 0.02 seconds
i got result in 0.02 seconds and accepted and still it is not showing my rank in submitted successfully windows
Yes it is..
Yes it is..
where
where
You're the first name on the
You're the first name on the second page?
hello my answer is coming
hello
my answer is coming correct in my system but after submotting it is showing wrong answer...... y??
list = []t =
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
is it necessary to do any catching of errors?
The input you are provided
The input you are provided will comply with the constraints in the problems statement.
I am reading this problem and
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 <=
That should say 1 <= Si <= 1000 and 1 <= Ti <= 1000.
Chef, the I/O is often
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
Did you see the sample I/O provided in the probelm?
who will be the winner for
who will be the winner for the foloowing case and how
2
10 100
100 10
Read the last sentence before
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
if it is not a tie then who should be winner ??
i cudnt c any other corner cases .
The winner is easily player
The winner is easily player 2. Read the problem statement again.
@Admins: thanks for fixing
@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,
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.
This is fixed.
it is showing wrong answer in
it is showing wrong answer in my code but it gives correct answer in my compiler
i have also tried the
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
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
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
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
umm i really dont think u should do that
some weird behavior in
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
Please let me know the reason of wrong answer in my submission.
The same problem everyone
The same problem everyone else has. You haven't read/understood the problem statement. Read it again.
coders who got wrong answere
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
@AMRITPAL thaks a lot, your comment really helped :)
AMRITPAL i cant get what you
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
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
@ashish read the test cases described in statements and u must got point
I'm reading in data in C++
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
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
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
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
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
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
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
Sorry please ignore my last comment , amritpal correctly pointed out the error in my interpretation , finaly got a correct answer :)
I am getting runtime
I am getting runtime error......can someone tell me exactly how to get rid of it?
It should be pretty obvious.
It should be pretty obvious. Read the input section.
i have added the scores and
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
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
@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
@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
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
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
what is wrong with this showing that wrong answer while i am getting correct answers on my pc.. :(
Do not post code here (FAQ).
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
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
^ 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
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
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
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
@admin could u pls show the input for which my program is being tested.....
never ever rely only on the
never ever rely only on the sample input output data ...read the problem statement carefully.....:D
For all : 1. I rectified the
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
@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
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
@admin
can u please clarify what im not calculating.
i still not getting it..
The problem statement has a
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
@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
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
Read the explanation of how the sample output is calculated.
is the question jus abt ...
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
@sysadmin ...can u tell me wat is the problem with my sol.
http://www.codechef.com/viewsolution/299753
Same as everyone else. The
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
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
Try this test case:
21 0
1 0
plz tell why my answer is
plz tell why my answer is wrong?
Same reason everyone else's
Same reason everyone else's is. Try reading the problem statement again (or the comments..)
i have made several changes
i have made several changes but still not working.
plz help.
my program code is 313607.
urgent
http://www.codechef.com/views
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
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
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
Because your main method doesn't return 0.
thnks Stephen its now k now i
thnks Stephen its now k now i understand.
hey my program is working
hey my program is working fine on my comp....but when i submit its givin runtime error pls help me...
thanks the_champ Shame !
thanks the_champ
Shame ! could not figure that out myself
@Stephen Merriman What's the
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
@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
@Admin
owh i get it sorry for troubling. thanks :)!
everytym i try to submit a
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
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
i m getting the correct output on my system..bt dont no why its getting wrong here ....plz help
You, like almost everyone
You, like almost everyone else in this thread, haven't read the problem statement. Read it again.
Seems like all the coders
Seems like all the coders around the world are the same hehe :P
/*the lead gameinput:scores
/*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
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
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.
Please read the FAQ.
@Admin: My solution is
@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
Can someone tell me what's wrong with my code?
http://www.codechef.com/viewsolution/406822
Earlier one was a wrong
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
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++
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
I'm afraid your solution is plain wrong. Read the problem statement again.
@Admin: My solution is
@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.
Same comment as above.
@Stephen: Thank you so much
@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
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
@Gayathri,
Why are you printing a "t" in between the two variables in the output?
Guru
@Admin Can you please let me
@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
You too should read the problem statement or my last few comments.
@stephen: If you look at the
@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
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
I'm afraid you don't seem to
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
@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
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
@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
#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
Read the explanation of the
Read the explanation of the sample input. You are solving the wrong problem.
@stephen:sir can u explain
@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
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
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
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
@Jason:
Please read the above comments. Your answer is there only. :)
@ Rajneesh, If you are
@ 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
You have a problem related to temp1 and temp2.
@Jason: Stephen is right! A
@Jason:
Stephen is right! A very small mistake! :)
@admin: I am getting same
@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
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
@admin : Got the error. Thank you..
@Stephen: My Lead game is
@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/
Url: http://www.codechef.com/viewsolution/435652
You're making the same
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
@stephen- sir , i have sent you a PM, please check.
thank you.
the solution i have submitted
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
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
#include int main() { int
please check my solution ,
Requires more of reading
i've learnt alot from this
@Admin Could you please give
can smebody help me??? its
Problem says "Once all the
why the compiler of code chef
reading skills are quite a
can any one help me in this
#include int max(int
#include int max(int
@raja_utkarsh: you are using
This problem has issues.
Dear...Admin..this is my
Here is my code that took
what's wrong,plz
#include #include int
we can attach stdlib.h or not
in my code i m using
@admin or any1 plz plz help
My code is running properly
My code is running properly
WINNING IS BASED ON TOTAL
i am getting the correct
Link for my solutions:
what the output should be
The logic they use to check
My code is running properly
Description is strange.
How is my code
#include int main() { int
can u tell me for which test
u need to add previous round
please check this
@ujjwal In your code there is
Can anybody please give the
Anyone please please help
I think that the main
Please tell me the problem
int main() { int
@admin i think you shud make
"The Manager of Siruseri
@akhilnandoo i support you.
Tricky question. Users who
@peeyush but the example