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
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(hard) » Team Selection

Team Selection

Problem code: TEAMSEL

  • Submit
  • All Submissions

One of the cherished customs of my childhood was choosing up sides for a cricket game. We did it this way: The two bullies of our gully would appoint themselves captains of the opposing teams, and then they would take turns picking other players. On each round, a captain would choose the most capable (or, towards the end, the least inept) player from the pool of remaining candidates, until everyone present had been assigned to one side or the other. The aim of this ritual was to produce two evenly matched teams and, along the way, to remind each of us of our precise ranking in the neighbourhood pecking order.

We all believed this was the fairest process, but does it ensure the fairest selection of players with evenly matched teams? We believed so, but then there were times when, as the game progressed we realized that the other team was stronger than ours and may be an exchange of a couple of players between the teams would have made them balanced. That scope of improvement seemed to be there...

Here, we need to find a way to create two evenly balanced teams for any game(or as evenly balanced as possible considering the strength of each player). A set of players must be divided into two teams. Each player must be on one team or the other; the number of player on the two teams must not differ by more than 1; each player will have a skill-point associated with him. The total skill-points of the players on each team should be as nearly equal as possible.(The absolute difference of the sum of skill-points of players in each team should be the least).

Input

The first line of input will contain the number of test cases 'T'(1<=T<=100). This is followed by 'T' test cases. Each test case starts with a blank line, followed by N, the total number of players. N lines will follow with the first line giving the skill-point of person 1; the second line, the skill-point of person 2; and so on. Each skill-point shall be an integer between 1 and 450. There shall be at most 100 players in all(1<=N<=100).

Output

Your output should be exactly '2T-1' lines. The output for each test case should be followed by a blank line, except the output for the last test case. Each odd numbered line should contain 2 numbers: the total skill-points of the players on one team, and the total skill-points of the players on the other team. Print the smaller sum first.

Example

Input:
4

3
90
200
100

10
2
3
10
5
8
9
7
3
5
2

10
1
1
1
1
1
1
1
1
1
9

8
87
100
28
67
68
41
67
1

Output:
190 200

27 27

5 13

229 230


Date: 2009-05-20
Time limit: 5s
Source limit: 50000
Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK


  • Submit

Comments

  • Login or Register to post a comment.

giribabu @ 30 May 2009 05:55 PM

I am not sure why my solution is not being accpeted.
Its working perfectly on my system. Is there a way to know how you give the input and match the output?

What should the program do when the wrong input is provided?
lets say the skill point entered is 500, what should be the expected behaviour?

ketansakaria @ 22 Jun 2009 06:11 PM

If possible, then mail the Input data for which the code is failed.

i0exception @ 30 Jun 2009 09:21 PM

It is not possible to mail the input data as of now. If you have any particular problems, post in the forums for hints about the approach.

jizo @ 6 Jul 2009 05:32 AM

I second the need for input data or at least output data. For what I can tell my solution works. But not sure what input data is causing it to produce incorrect results. Also what should be output if team size is 1? I line with 0 x where x is skill points or a line with just x?

i0exception @ 6 Jul 2009 05:17 PM

@jeremy Print the smaller number first.

ketansakaria @ 14 Jul 2009 03:55 PM

I tried to solve TEAMSEL problem using Min-Max algorithm. Program ran for 0.35 seconds and it produced wrong output. while the counter on the process bar on right side has gone to (8). Does it mean that it gave wrong output for 8th test case ???

admin 2 @ 29 Jul 2009 08:59 PM

That's not necessary. Even if it fails one test case, you get the status as WA.

I did some experiment with

skywalker @ 23 Aug 2009 10:15 AM
I did some experiment with this problem. I think i have optimized my code to a fair enough extent. Your conditions say 5 seconds for running about a 100 test cases. I executed the first 99 cases, and threw an Exception. Your System tells me runtime error, time taken = 0.74 secs However, when i try to throw the exception at case number 101, it says time limit exceeded, time taked 7.3 secs Now Clearly, I cant be entering an infinite loop in the 100th case. I dont understand the logic of "Time Out". You can verify my submission Ids i) 78005 and ii) 77998 Besides there are successful java submissions which have taken over 20 seconds, why should i be shown a time exeeded error at just 7-8 seconds

I did some experiment with

skywalker @ 23 Aug 2009 10:15 AM
I did some experiment with this problem. I think i have optimized my code to a fair enough extent. Your conditions say 5 seconds for running about a 100 test cases. I executed the first 99 cases, and threw an Exception. Your System tells me runtime error, time taken = 0.74 secs However, when i try to throw the exception at case number 101, it says time limit exceeded, time taked 7.3 secs Now Clearly, I cant be entering an infinite loop in the 100th case. I dont understand the logic of "Time Out". You can verify my submission Ids i) 78005 and ii) 77998 Besides there are successful java submissions which have taken over 20 seconds, why should i be shown a time exceeded error at just 7-8 seconds

Your code is run on multiple

triplem @ 23 Aug 2009 10:50 AM

Your code is run on multiple input files. If your code has not produced the correct answer for a file, the time reported is the time at that point.

The first file is likely to be small input cases, which is why your code only takes 0.74 seconds to virtually complete it before throwing the exception. If you put the exception on the 101st case (which doesn't exist, ie you'll never throw an exception) it is getting onto other more complicated input files and running out of time on those.

So you'll need to work on improving your algorithm to work with large test cases.

The fact there are multiple input files + that the time reported is the sum of all input files is mentioned in the FAQ which you should read.

I did read the relevant FAQ

skywalker @ 23 Aug 2009 02:48 PM
I did read the relevant FAQ entry regarding this, but only after i had made a post here. Thanks for clarification anyway

Hi Admin, As per problem

r.r.madhav @ 24 Aug 2009 08:28 PM
Hi Admin, As per problem statement: "Each player must be on one team or the other; the number of player on the two teams must not differ by more than 1;" Then how come the output for first illustrated case: 3 90 200 100 ..be 190 200 ? Thanks, Madhav

Team 1 has 2 players with

admin @ 24 Aug 2009 09:09 PM

Team 1 has 2 players with scores 100 and 90 and Team2 has 1 player with score 200.

but player with score 3 has

r.r.madhav @ 25 Aug 2009 11:32 AM
but player with score 3 has not been selected in any team. As per problem constraints, every player must be in at least one team.

Read the input specifications

admin @ 25 Aug 2009 01:23 PM

Read the input specifications again. 3 is the number of players and not the strength value of one of the players.

Its working perfectly on my

uvaraj @ 31 Aug 2009 09:24 PM

Its working perfectly on my system. I have tried few test cases on my system everything works fine. Can you please give me the hint where my code fails? is it for all the test cases or just few? or Is it because of the boundry conditions? is it because of time?  Could you give me any hint, that can help me to find the root cause.

Its working perfectly on my

uvaraj @ 31 Aug 2009 09:24 PM

Its working perfectly on my system. I have tried few test cases on my system everything works fine. Can you please give me the hint where my code fails? is it for all the test cases or just few? or Is it because of the boundry conditions? is it because of time?  Could you give me any hint, that can help me to find the root cause.

 

Thanks

Uvaraj

You can try brute-forcing

admin @ 31 Aug 2009 09:39 PM

You can try brute-forcing through small samples and checking out if the answers match. We can't give specific help regarding this problem as we use it for recruitment purposes.

    Questions rules  and

dhirajkumar @ 4 Sep 2009 05:53 PM

 

 

Questions rules  and given answers are not matching :

 

Rules here say :
1 )Each player must be on one team or the other;  2) the number of player on
the two teams must not differ by more than 1;
3 90 200 100

 

Team 1 :200

Team 2: 90,100

 

isn' t rule number 1 broken ? why 3 is not selected ?

 

are we allowed to break any rule?

 

 

In another Question :

 


10
1
1
1
1
1
1
1
1
1
9

 

how come is the output

5 13

 

i can see there are 11 players

and to me output seems to be :

 

14 14

 

 

 

3 is the number of players

admin @ 4 Sep 2009 06:57 PM

3 is the number of players and not one of the players.

can i have test case input

stupid_coder @ 8 Sep 2009 07:51 PM

can i have test case input file for this problem.

currently it is not possible

admin @ 9 Sep 2009 02:27 PM

currently it is not possible to give you the input file for the problem. The major reason for this being that people can hardcode the values if the input file is made public.

My solution is not being

nimesh priyodit @ 13 Sep 2009 09:12 AM

My solution is not being accepted (even not processed) with this error message, as soon as i press the submit button:

 

warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/html/codechefbeta/codechef/sites/all/modules/codechef_judge/codechef_judge.module on line 48.

 

I could not understand if something is wrong with my code, as it is running fine on my computer. Need your kind guidance.

Regards,

Nimesh

Hi Admin, The error soon

nimesh priyodit @ 13 Sep 2009 09:30 AM

Hi Admin,

The error soon after pressing the submit key is this:

 

 

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

 

Thanks and Regards,

Nimesh

Hi Admin, Does the time limit

nimesh priyodit @ 15 Sep 2009 03:00 PM

Hi Admin,

Does the time limit = 5 sec mean that a java code should take at most 10 Seconds to resolve a file consisting of 100 test cases of 100 players in each test case?

 

Thanks in advance for the help.

Nimesh

My code submission results in

codeczar @ 15 Sep 2009 05:03 PM

My code submission results in a compile error. Can I get the compilation error. The code compiles and runs fine on my machine. I have Java 1.6.0_11 on my system. Please help.

I have submitted the code and

bits176 @ 16 Sep 2009 04:24 AM

I have submitted the code and it is working pretty well on my system for all the inputs, I don't understand why it failing here, any clue on this??

@Ankur Check

admin @ 16 Sep 2009 01:21 PM
@Ankur Check www.codechef.com/help for a sample solution in your language. @Nandan It is failing because you are producing the wrong answer for certain inputs.

I have submitted the code for

karthkvishnu @ 18 Sep 2009 02:49 AM
I have submitted the code for this problem which works well in my system. This is my first submission. I dont know how the input is fed to the program in your side. I need a simple sample showing me how the program is executed in your system.

and i have used the latest c#

karthkvishnu @ 18 Sep 2009 02:50 AM
and i have used the latest c# version. I dunno which version u guys use.. Enlighten me abt this too..

or can i get the the test

karthkvishnu @ 18 Sep 2009 03:06 AM
or can i get the the test case that you use to verify

You have to read the input

admin @ 18 Sep 2009 02:20 PM
You have to read the input from stdin and output the answers to stdout. Currently it is not possible to provide the test cases against which a solution is judged.

Can u tel me where my

karthkvishnu @ 18 Sep 2009 09:16 PM
Can u tel me where my solution went wrong? I'm unable to proceed as i dont know where i went wrong cuz de solution works fine in my system..

Currently we cannot do that

admin @ 18 Sep 2009 11:08 PM
Currently we cannot do that as we use this problem for recruitment purposes.

Its working on my

bathia.pranjal @ 20 Sep 2009 08:18 PM
Its working on my system..would you please tell me for which input my program is giving wrong answer..or else please provide the input file..

I dont under stand why these

sumanta.dey2001 @ 4 Oct 2009 09:06 PM

I dont under stand why these kind of NP complete problems, code chef used to post.

what all you are looking for a very good heuristic ???

 

I dont under stand why these

sumanta.dey2001 @ 4 Oct 2009 09:06 PM

I dont under stand why these kind of NP complete problems, code chef used to post.

what all you are looking for a very good heuristic ???

 

I dont under stand why these

sumanta.dey2001 @ 4 Oct 2009 09:06 PM

I dont under stand why these kind of NP complete problems, code chef used to post.

what all you are looking for a very good heuristic ???

 

Nope, we aren't looking for

admin @ 5 Oct 2009 02:48 PM

Nope, we aren't looking for that.

The solution I submitted

vijaymathew @ 10 Oct 2009 11:37 PM

The solution I submitted failed with a runtime error. I ran this program against lots of test cases. I am not able to reproduce a "crash". The program exits with the return code '1' in case of a boundary check fail. Is this OK or should I handle invalid input some other way?

Thank you,

-- Vijay

Hi, I there any way to know

akhilkodali @ 15 Oct 2009 03:14 AM

Hi,

I there any way to know for which case my submissions are going wrong.

Is it the format or the value of the output?

No, currently it is not

admin @ 15 Oct 2009 02:00 PM

No, currently it is not possible. The output format is specified in the problem statement. If you stick to those specifications, you shouldn't have any problems.

From the input it seems that

balasreeni @ 20 Oct 2009 03:51 PM

From the input it seems that 1 player is also a valid situation - for e.g. if there is only one player with 10 points, then the answer would be 0 10. Is this true? If no then the input condition needs to be 1 < N <= 100

The input specifications are

admin @ 20 Oct 2009 04:26 PM

The input specifications are correct :)

For the following

shasankar @ 27 Oct 2009 05:58 PM

For the following input

1

5
1
2
3
-15
2

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

Should I consider -15 as 1.. or should I skip(ignore) -15 and again ask for input?

The problem statement clearly

triplem @ 28 Oct 2009 04:42 PM

The problem statement clearly says each skill point in the input will be between 1 and 450.

Hi, What shoulbe be the

nandish_83 @ 31 Oct 2009 03:37 PM

Hi,

What shoulbe be the output if we have only one player with his weight as 1

0 1

or  just

1

I understand that the smallest number needs to be printed first, bit since the other does not exists at all in this case, is it required to print the 0

 

Regards,

Nandish

 

It tells you to print out two

triplem @ 31 Oct 2009 04:03 PM

It tells you to print out two numbers always; since there are no players in one team, you print a 0.

Thanks Stephen, I have

nandish_83 @ 31 Oct 2009 09:06 PM

Thanks Stephen,

I have executed the program for many test cases and it works fine with all inputs, I donno where its going wrong. I am running short of test cases.Any trivial test case if you guys can share will be much appreciated. Hope this is not against the contest rule.

 

Hi Admin, I have compiled my

nandish_83 @ 1 Nov 2009 06:32 AM

Hi Admin,

I have compiled my program on VC++, Dev C++ and Linux g++ compiler.

The same code gave two  different results on VC++ and (Linux and Dev C++), though it may  look a bit strange.

The input

1 5 27 108 9 207 54 gave :  198 207 on (Linux and Dev C++). which is wrong I guess, and for the same input on VC++ I got: 189 216 which is correct. Can you please advise me on this. My recent submission has the code onwhich  I am facing this issue

 

Regards,

Nandish

When I was captain of a pool

gtoal @ 13 Nov 2009 01:39 AM

When I was captain of a pool team some years ago, our opponents would play their people in order of strength (let's say 5 4 3 2 1).  It didn't take a genius to work out that if we put in our worst player first, we'd always have an advantage, ie we would play 1' 5' 4' 3' 2', so that the games were 5 vs 1', 4 vs 5', 3 vs 4', 2 vs 3' and 1 vs 2'.

Actually the details were *slightly* more complex; we'd actually use 2 duffers against their best players to get a more reliable 3:2 advantage, and they generally also played in reverse order so that their best player & captain would play last, since against most teams, the last game was the decider.  With us it was a throw-away in their favor but they'd already lost by then.

We got away with this several times before they got wise to us and adapted.

A more interesting problem would be programming the above strategy against a team that learns and adapts even during a single set of games in a match.

 

Karmarkar-Karp.

gtoal @ 13 Nov 2009 02:19 AM

Karmarkar-Karp.

Do not post code here. This

admin @ 13 Nov 2009 09:53 PM

Do not post code here. This is a recruitment problem, so we expect people to come up with solutions themselves.

"currently it is not possible

gtoal @ 14 Nov 2009 04:38 AM

"currently it is not possible to give you the input file for the problem. The major reason for this being that people can hardcode the values if the input file is made public. "

Absolutely.  Plus a blind pass/fail is far better at making you look at all your code (like the pascal validation suite used to do).

Since partitioning *is* an NP-complete problem, if the tests were random it is possible that some test solution has a less good value than one our code may provide.  Since they are sure they have definitive answers for all tests, the conclusion must be that 1) all tests over a certain size that are from random data have a difference <= 1; and 2) if there are any tests of a size beyond that which can be brute-forced where the difference is > 1, then they're not random but carefully constructed edge cases, probably based on a smaller subset of data that *was* brute-forced and then added to in a controlled way.

I suspect that many solutions (mine included) are right for all small sets and most if not all random large sets, but not for some of these edge cases.  if that is indeed what is going on, it would be cool if people could post some edge cases and we can compare what results we get.

FYI I'm playing with a sort of 'reverse bully' algorithm for the simple greedy part of the computation, pairing off the best and the worst as I mentioned in the post above.  This has the benefit of giving you a wide range of differences between all the pairs, which gives you more data to work with, than the simple bully case where all the differences between pairs are minimal.  It seems to converge on a best answer much faster in the average case.  (Not taking any randomisation/hill climbing etc into account, just looking at the basic unit of computation)

 

The fact that a general form

triplem @ 14 Nov 2009 06:39 AM

The fact that a general form of this problem is NP-complete means nothing. The input constraints are small enough that any input that complies with the constraints should be solvable by the right algorithm inside the time limit.

 

Stephen, if you mean taking

gtoal @ 15 Nov 2009 09:18 AM

Stephen, if you mean taking advantage of the constraints to do a knapsack implementation, that was my first thought, but since the folks here keep mentioning that it's used as a recruitment question, I dismissed that option: no-one would want to hire a programmer who proposed a solution with two such obvious flaws.  The first flaw, relatively minor, being that the solution doesn't scale when the customer comes back with a modified spec, requiring a complete rewrite; the second being more significant - do you give your customer what he asks for or what he needs?  This customer clearly needs to partition the players into 2 teams.  The knapsack solution doesn't do that, it just tells you the difference in strength between the two teams but not the teams themselves. Admittedly this is exactly what is asked for in the question, but it is straining the limits of the artificial environment of test questions to believe that this is what is really wanted.  I guess your average 'take the money and run' consulting company is happy when they get the opportunity to do multiple rewrites, but I wouldn't want to work for them :-)

Whether this is used as a

triplem @ 15 Nov 2009 09:43 AM

Whether this is used as a recruitment question or not, it is a problem in the practice section on Codechef, and every single question here and the thousands on the other online judge websites are all designed for the same purpose; you have to output exactly what is required and nothing more; it is nothing to do with scalability or, in this case, exactly what the teams are. It's just the way all programming competitions are run.

(I may well be wrong, and I haven't even solved this problem myself, but I just would be extremely surprised if this problem was so drastically different from the other thousands that are out there.)

Hi, my program passed with

javasoul @ 23 Nov 2009 11:00 AM

Hi,

my program passed with all the test cases -wotever i tried..

but failed here - got WA.

can somebody post here some more/many diffirent testcases?

is the program supposed to

sreejith @ 23 Nov 2009 11:32 AM

is the program supposed to check the values of t,n & skill point to check is it within its specified limit .

 

i am using scanf to take values or is it taken from a file.

The problem statement tells

triplem @ 23 Nov 2009 12:22 PM

The problem statement tells you what range the input lies in. The problem statement isn't going to tell you something that is wrong :P

You read and write from standard input + standard output.

is the program supposed to

sreejith @ 23 Nov 2009 07:15 PM

is the program supposed to check the values of t,n & skill point to check is it within its specified limit .

 

i am using scanf to take values or is it taken from a file.

Hi, I am not able to see the

devvrr @ 24 Nov 2009 05:27 PM

Hi,

I am not able to see the successful submissions for this problem(infact for any other problem). It gives the below message

"Oops, we couldn't seem to load the successfull submission. Try again soon."

 

Thanks

Hi, I am not able to see the

devvrr @ 24 Nov 2009 05:30 PM

Hi,
I am not able to see the successful submissions for this problem(infact for any other problem).
It is giving the below message.

"Oops, we couldn't seem to load the successfull submission. Try again soon."

Thanks

@ Admin: what o/p shuld d

sreejith @ 24 Nov 2009 11:53 PM

@ Admin:

what o/p shuld d program give if d value of 't' or 'n' or skill point is out of bound??

@ Admin: what o/p shuld d

sreejith @ 24 Nov 2009 11:57 PM

@ Admin:

what o/p shuld d program give if d value of 't' or 'n' or skill point is out of bound??

And which one shuld be used

a)Is codeblocks on windows  fine   or

b)Linux(i have ubuntu) is preferred

The problem statement tells

triplem @ 25 Nov 2009 05:29 AM

The problem statement tells you the input values are within that range. If they weren't going to be in that range, it wouldn't have told you so :P

Hi Admin, I am new to this

coder63 @ 26 Nov 2009 02:38 PM

Hi Admin,

I am new to this site.

When I submit my solution, it says "time limit exceeded". But when, by mistake I submit the same solution with my DEBUG flag on i.e. some debug messages are printed, then it says "incorrect solution" very shortly. But I would expect even in later case, the time limit to exceed. How is it possible? I was assuming that first you let the whole output to get generated and then match the output, and hence in both the cases it should give "time limit exceeded". But do you simultaneously also check for correctness of whatever output has generated so far, while the program is still running?

Thanks,

There could be multiple input

triplem @ 26 Nov 2009 02:49 PM

There could be multiple input files. The judge reports what happens with the first incorrect input file, so it is easy to get the results you said.

@ Admin: i am gettin correct

sreejith @ 10 Dec 2009 01:44 AM
@ Admin: i am gettin correct answer at another site while using d same spoj engine that codechef uses. plss can u tell me y ?? i can send u d link if u want.

Yeah sure, send us the link.

admin @ 10 Dec 2009 02:19 PM

Yeah sure, send us the link.

I have submitted my solution

ds.sundar @ 16 Dec 2009 06:15 PM

I have submitted my solution but the result was wrong answer. Can you provide a partial test case file. For example with some 60 to 70 test cases.  Not the one used to verify the answer.

 

Thanks & Regards

Sundaram. D

It would not be too difficult

admin @ 16 Dec 2009 06:35 PM

It would not be too difficult to create sample test cases on your own.

Hi Anirudha, does exceeding

nagendracse @ 16 Dec 2009 07:11 PM

Hi Anirudha,

does exceeding the time limit mean u answer is wrong. Or can i assume that for some of the test cases it passed but the time taken was much more than the requirement.

TLE means that your program

admin @ 16 Dec 2009 07:24 PM

TLE means that your program took more than the stipulated time limit to produce a result. Please don't assume anything other than this.

Codechef keep showing me

praveen.sinha @ 18 Dec 2009 06:15 PM

Codechef keep showing me runtime errors, I have checked and tested my solution on my local system with wide array of tests and all seems to pass without any issue. I know you can't share the test cases but atleast can you send across the exception thrown.

Please make sure that you are

admin @ 18 Dec 2009 07:23 PM

Please make sure that you are taking input in accordance with the input specs. And that you are returning 0 at the end.

My program cannot return 0 as

praveen.sinha @ 19 Dec 2009 05:44 PM

My program cannot return 0 as its written in java. I am taking input in accordance and am throwing an exception whenever wrong input is made. For an example in my local environment this is the input I am entering

3

1
100

3
10
10
450

5
1
1
1
1
450

Output:

0 100

20 450

3 451

is this not the desired behavior? I have checked extensively with the edge cases and on the boundaries without failure in my dev environment. It would be good if you can send more informative error logs. At this point everything on my environment is working and everything on the codechef is failing, which makes me think wheter its a problem wiht my code or a limitation of your engine.

Hi Admin, I understand that

nandish_83 @ 21 Dec 2009 04:20 PM

Hi Admin,

I understand that this problem is used for recruitment purpose. My solution works for all the cases that I have tried.  To be honest  I am trying to break my solution for two months. It passes for all the test cases I have used. Would be great if atleast one failing test case is sent.

I had posetd some issues on 1st Nov,2009 06:32:59. which was not answered. Any help would be greatly appreciated.

 

 

Regards,

Nandish

Hi Admin,I understand that

nandish_83 @ 21 Dec 2009 04:21 PM

Hi Admin,

I understand that this problem is used for recruitment purpose. My solution works for all the cases that I have tried.  To be honest  I am trying to break my solution for two months. It passes for all the test cases I have used. Would be great if atleast one failing test case is sent.

I had posetd some issues on 1st Nov,2009 06:32:59. which was not answered. Any help would be greatly appreciated.



Regards,

Nandish

We use g++. So make sure you

admin @ 21 Dec 2009 04:24 PM

We use g++. So make sure you get correct answers using that. I have no idea about VC++. Generating random test cases might not be a good idea for this problem. Test it against corner cases which you might think would fail.

 

to admin... i have a doubt

parth_gupta @ 23 Dec 2009 10:48 PM

to admin...

i have a doubt about the output..

is the output of each test cases should be printed together at the end or individual for each test case..?

for each test case output should follow the input or the output for each test case should come at last together.

It makes no difference

triplem @ 24 Dec 2009 02:32 AM

It makes no difference whatsoever. There is no way the judge can tell at what time you are printing things out, only the output matters.

How the input file has to be

divyas @ 27 Dec 2009 01:18 AM

How the input file has to be provided to the script(ant particular convention)? I mean will it be provided, as command line arguement or what? Also is there any specific name for the output file to be generated?

You must use standard

triplem @ 27 Dec 2009 02:44 AM

You must use standard input/output streams.

Oh is that compulsory? In my

divyas @ 27 Dec 2009 03:05 AM

Oh is that compulsory? In my code I assumed that an input file will be provided while running the script & an output file will be generated corresponding to that. Could that be cause of Runtime Error.

Yes, it is compulsory.

triplem @ 27 Dec 2009 05:03 AM

Yes, it is compulsory.

Hi Admin,   I have not

praveen.sinha @ 31 Dec 2009 12:48 PM

Hi Admin,

 

I have not recieved any reply for my earlier query at 19th Dec,2009 17:44:16. I am still getting a NZEC, which I am sure should not be the case considering th eamount of test cases I have tried. If there is some input which is crashing it it would be of great help if you can provide me with that.

 

Regards,

Praveen

 

 

 

Hi Admin, I have small

murthykavali @ 31 Dec 2009 01:37 PM

Hi Admin,

I have small doubt.

According to the problem output should be 2t-1 lines.

So for the last output do I need to do println("result") or print("result"); ?

 

@for others One more typical test case( I guess):

1

9

100

120

265

215

100

100

300

200

30

 

output:

715 715

@Praveen - of course it would

triplem @ 31 Dec 2009 02:03 PM

@Praveen - of course it would be a great help if you were given the test case. That is exactly why you will not be given the test case. You have to debug your code yourself.

@R C R K - println. Though if it is using a standard judge it should make no difference.

While registering I choosed

divyas @ 1 Jan 2010 03:49 PM

While registering I choosed python as my prefered language, can I change the language preference now?

Click 'Account' at the top

triplem @ 1 Jan 2010 03:58 PM

Click 'Account' at the top right of the screen.

Time shown for my code is

divyas @ 1 Jan 2010 07:27 PM

Time shown for my code is 0.00 and I get the wrong answer message. How is that possbile? I dont understand,  how come the run time be 0.00.

Why are we not able to submit

nandish_83 @ 5 Jan 2010 04:26 PM

Why are we not able to submit our solutions? Is the site under maintenance?

 

Regards,

Nandish

heylo i have written a DP

jknair @ 6 Jan 2010 01:12 PM

heylo 
i have written a DP approach to this problem and it solves all the test cases that i could come up with
1 player with a team skill ... 100 players with skill 450 all the boundaries are checked and working the judge shows 0.04 secs of running time and then wrong answer ........ NO CLUE whats wrong 

neways if the admin can chk it would be greatly helpful id jknair and submission id [160583]

thanks 
PS : any test cases that u can think that could break the program ??

As it is a recruitment

admin @ 6 Jan 2010 04:55 PM

As it is a recruitment problem, we cannot give out specific information.

I think as per most of the

KulbhushanBhalerao @ 11 Jan 2010 11:25 PM

I think as per most of the programmers here, I think the example given here doesn't seems to be accurate.

e.g. for the output of, 10,1,1,1,...,1,1,1,1,9 the best output can be 14 14 as it can cover most of the players and yeah it can divide teams in equal number with equal skills.

**Anyway, Can anyone help me to run my program?

I have a input.txt file with the SelectTeam.java class. How can I upload both the files at the same location so that my Class gets the input.txt file correctly.

 

Thanks a lot,

Kulbhushan

Also my program seems to be

KulbhushanBhalerao @ 11 Jan 2010 11:32 PM

Also my program seems to be working smoothly, if I run in my Eclipse environment for any number of testcases and any numbers of skilled players.

Or do you want me to provide input hardcoded in source??

Kulbhushan

The sample output is correct.

triplem @ 12 Jan 2010 02:04 AM

The sample output is correct. As the problem statement mentions, the first number in each set is the number of players; 10 isn't one of the skill points.

You cannot upload a text file; you are to use the standard input/output streams.

The time limit is given as

vrajesh1989 @ 14 Jan 2010 11:45 PM

The time limit is given as 5s. But there are solutions that have greater running time (in C++) and got accepted.

FAQ

triplem @ 15 Jan 2010 02:08 AM

FAQ

Please let me know how can I

prateekg @ 17 Jan 2010 02:16 AM

Please let me know how can I submit my code.

I am reading a file from my bin folder (inputFile for all test cases) and creating a new text file(output file) in bin folder.

Please guide me if I am supposed to use any other way.

 

You must use standard

triplem @ 17 Jan 2010 02:25 AM

You must use standard input/output streams.

I am using standard features

prateekg @ 17 Jan 2010 02:37 AM

I am using standard features only and reading data from a test file. My question is does the location of the files ( "../input.txt", "../output.txt")  will be an issue or should I change it to some other location ?

last message continued... Do

prateekg @ 17 Jan 2010 02:40 AM

last message continued... Do I need to take input from console and prompt user to input numbers or filepath?

I told you already, use

triplem @ 17 Jan 2010 03:42 AM

I told you already, use standard input/output streams. Do not use files.

My Submission Id is 169633

prateekg @ 17 Jan 2010 06:58 AM

My Submission Id is 169633 and Judges considering it as a wrong answer. The logic seems to work fine for all test cases i could think of. Any insinuation what went wrong (I mean the test case)  please..........  :)

Another thing is the solution was taking only  0.12 - 0.15 S on my machine while judges are saying that its taking more than 2 seconds, no idea why... :(

 


I have formatted my output

prateekg @ 17 Jan 2010 11:38 AM

I have formatted my output and made it exactly what it should be.

Please tell me if what kind of problem is there in the output is it a logical error which is generating wrong sums?

Is it the output formatting error (not in the proper format)?

or is it the output formatting when using negative cases like cases with decimal, negative or null values?

 

Cause logically it is passing each and every test case on my system well with in .2 seconds even when I am taking 60 test cases at a time with many different player counts.

Hi Admin, My solution is

venkat.muvva @ 18 Jan 2010 09:32 PM

Hi Admin,

My solution is working fine and giving correct output for all the test cases. But in code chef it is giving
Wrong Answer. Can you please provide me with the test case for which it is failing?

Is it so (according to what

mahul_bh @ 23 Jan 2010 01:29 PM

Is it so (according to what Graham Toal has said) that your judge might pass a solution as correct, which might as well fail for a test case which is also within the input pre-conditions that have been laid down?

Also, i see that my solution is giving a WA with an execution time of 0.00. Does this mean that my solution is failing for some of the smaller test cases at the start?

My solution works for the

vaibhavk @ 23 Jan 2010 08:11 PM

My solution works for the given test cases, but says wrong answer when submitted. Can you PLEASE give extra test cases? I'm not asking for the test cases used for evaluation (obviously, as stated earlier, then you could just hard-code).

Thanks

@ Mahul yes, and yes. @

triplem @ 24 Jan 2010 02:46 AM

@ Mahul yes, and yes.

@ Vaibhav. No. You are expected to come up with your own test cases; that is part of the problem. You will not be given any.

Getting wrong anwser after

kapilreddy @ 28 Jan 2010 09:29 PM

Getting wrong anwser after dealing couple of runtime errors :(. I need to come up with really good input test cases now.

Here is one of the odd test

kapilreddy @ 29 Jan 2010 12:03 AM

Here is one of the odd test case. I have been able to produce good output with all the testcases but here is one that is making the output go bad again

1

23
1
1
1
1
1
5
5
5
5
5
5
5
5
8
8
8
8
8
8
8
9
10
450

got the above test case

kapilreddy @ 29 Jan 2010 01:55 AM

got the above test case working but still no luck :|

Can u tell me whats wrong

shobhitsahay @ 30 Jan 2010 03:27 AM

Can u tell me whats wrong with my submission..

its working for all the cases mentioned in the probleam as well as in the comment section..

also it is giving correct result for all the test cases i have tried..

is there something related to the problem output structure i have misinterpreted..

i have read the problem about 10 times..

plz help me out on this one..

my submission id is 174951..

Have tested with test case

kapilreddy @ 30 Jan 2010 09:05 AM

Have tested with test case above and also try to input big test cases like with 100 players or something. I am also hard time with but this is your best bet.

@kapil i have tried test

shobhitsahay @ 30 Jan 2010 10:31 AM

@kapil i have tried test cases of 100 players..

it works fine..

@admin

plz help out..

just tell me is my code failing for any input or is it because of some i/p/ o/p format..

well input and output format

kapilreddy @ 30 Jan 2010 03:22 PM

well input and output format is defined in statement. I had the same impression as you but my output is failing for some cases. :| and it still it is.

 

now i think i need some

shobhitsahay @ 30 Jan 2010 03:33 PM

now i think i need some optimization of my code..

time limit exceeding..

@kapil actually there was bug in my code..

@kapil. What ouput do you get

akhilhandoo @ 31 Jan 2010 08:40 AM

@kapil.

What ouput do you get for your 23 element input ??

I have submitted solution

niren @ 31 Jan 2010 12:26 PM

I have submitted solution ID=175623, but it shows wrong answer.
All the testcases mentioned with the problem statement comes out correct on my system.
So is it possible to get the details of testcase(s) which is/are failing when the code is submitted.

Appreciate some details. Thanks

plz take alook at my

shobhitsahay @ 31 Jan 2010 07:15 PM

plz take alook at my submission 17649..

i think its giving all correct answers..

is it because of some memory issues that my solution isn't working..

or is it really faiiling for some case..

plz reply..

@admin i think i am having

shobhitsahay @ 2 Feb 2010 11:48 PM

@admin

i think i am having some trouble regarding the input..

please help me..

my algorithm is correct and working for around 100 test cases i have tried..

i have made more than 20 submissions for this..

u have to tell me whats wrong wid my code..

one learns by his mistake..

but for that one had to be aware of what is he doing wrong..

plz check my solution..

Hi Admin, It would be great,

swshuk @ 23 Feb 2010 12:05 AM

Hi Admin,

It would be great, if, you could tell us, while submitting the solution, for what test case the program failed.

It would be a great help, because right now I am clueless what to do. My program is working for all the test cases I tried. Even the ones mentioned in forum.

Please help.

 

swapnil

Coming up with your own test

triplem @ 23 Feb 2010 07:15 AM

Coming up with your own test cases is part of the problem. You won't be given any.

Hi Admin,   problem statement

swshuk @ 23 Feb 2010 03:28 PM

Hi Admin,

 

problem statement says:

Your output should be exactly '2T-1' lines.

in the given example T=4

so the output shoudl be 2(4)-1 = 7

but output contains 4 lines.

Please clarify..

Ok sorry for the above

swshuk @ 23 Feb 2010 03:33 PM

Ok sorry for the above question, I think I got it.

Its including the empty lines as well.

It says time limit exceeded.

atishay811 @ 6 Apr 2010 09:51 PM

It says time limit exceeded. I agree that more optimal solutions may be possible. But is there a way to know how many test cases were passed before time limit exceeded. Also are you checking for 5s as time limit?

hey, there seems to be a bug

nan_sr @ 14 Apr 2010 11:21 AM

hey, there seems to be a bug in the submission page: it does not reset state after submission. I accidentally clicked on the button a few days after I had made a submission (I use session browsing on firefox) and it treated that to be a new submission -actually it should have flagged an error or disabled the submit button till new submit data was provided

what shoudl be the output if

khatriankit @ 3 May 2010 11:26 PM

what shoudl be the output if one enters no of players as 1?

is 0 1 the correct answer for this case?

Finally getting desired

kapilreddy @ 30 May 2010 12:46 AM

Finally getting desired output but now time limit exceeded!!!! i think need to rework the code which seems hopeless

I have feeling that i am

kapilreddy @ 14 Jun 2010 05:16 PM

I have feeling that i am really close now getting running time of 0.6 seconds but wrong output must be some really large input or I am still missing something.

Hi Admin, I ran my solution

rajeshmr @ 5 Jul 2010 03:01 PM

Hi Admin,

I ran my solution using the method mentioned in the FAQ, i.e. using < in.tx > and out.txt. It used the same test case given in the sample and got the exact same output, however the result shows wrong result. What could be wrong?

 

Thanks!

Rajesh

@admin in last test case

coolsainideepak @ 31 Aug 2010 08:09 PM

@admin

in last test case output sholud be

229 250

No it shouldn't.

triplem @ 1 Sep 2010 02:35 AM

No it shouldn't.

when I submit the solution it

anurag_aggarwal @ 1 Sep 2010 08:17 PM

when I submit the solution

it says solution to this problem cannot be submited in this contest

what does " :( internal error

jidmis @ 17 Oct 2010 11:31 PM

what does

" :( internal error occurred " mean ?

(No subject)

thechamp @ 18 Nov 2010 02:19 AM

@admin:kindly help it's

rockstar @ 24 Nov 2010 07:23 PM

@admin:kindly help

it's always givin TLE

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

disregard last.

rockstar @ 25 Nov 2010 10:39 PM

disregard last.

@admin got the code working

rockstar @ 26 Nov 2010 02:23 PM

@admin

got the code working for ~90 cases in 0.00 secs

however last few cases are causin some error at 0.03 secs.

i have made the code compatible for large inputs.

you can verify it:

383033

383029

I have test case that

devvrr @ 11 Jan 2011 12:34 PM

I have test case that produces wrong answer with the currently accepted fastest-solution(by sunilp). I reported this to admin more than 6 months ago. I still see that this solution is listed in the successful submissions.

Hi, This might be more than a

snktagarwal @ 20 Jan 2011 11:00 AM

Hi,

This might be more than a help to ask guys here, but I tried two major techniques. DP( which used awful amount of memory but timed out on the above test cases. It had abt 1 sec on a test case of 100 elements and thus could not suffice :-/. ). Then I tried to use a culling based technique, which tried to enumerate options and found the best one. It seems that both are of no great use. Could it be a nice hint for me, that either of my techniques would finally pass the test cases after optimization ? Or that I should start to think aloud and afresh!?

@Admin ,@ Stephen: Please

manoharsingh23 @ 21 Jan 2011 11:31 AM

@Admin ,@ Stephen:

Please check the soln http://www.codechef.com/viewsolution/427650.I checked for many values and it is giving correct values but on judge WA.Is it representation error or its giving wrong values .. PLz Plz check it.

Thank you.

Somebody from Admin Please

manoharsingh23 @ 22 Jan 2011 08:04 AM

Somebody from Admin Please help.... http://www.codechef.com/viewsolution/427650

8 //the number of

suresh77 @ 23 Jan 2011 03:03 PM

8	//the number of players
87
100
28
67
68
41
67
1
What is wrong if my answer is 
224 235

For the given input

suresh77 @ 23 Jan 2011 03:09 PM

For the given input values

8	//the number of players
87
100
28
67
68
41
67
1
What is wrong if my answer is 
224 235
Please Answer.....because i think that i am getting a wrong answer to my submission due to this test case.....

ok sorry!!! Just got confused

suresh77 @ 23 Jan 2011 03:48 PM

ok sorry!!! Just got confused somewhere.....

Is it possible to solve this

manoharsingh23 @ 28 Jan 2011 10:23 AM

Is it possible to solve this problem in Polynomial time?? I think its an NP complete problem , isn't it??

Hi Admin The program i

amarnathraju @ 29 Jan 2011 11:12 AM

Hi Admin

The program i submitted gives correct solutions for all the test cases i gave. But still i m getting a notification of "wrong answer". Can u please tell me for which test case my program doesn't run. Or what is the problem with it??

Hi Admin,   I have run many

moshu123 @ 11 Feb 2011 10:53 AM

Hi Admin,

 

I have run many test cases, even for skill point upto 10000, but it is not failing for anyone.

Could you please tell just the one test case, that my submission is failing (id # 453376).

 

Thanks

@Admin What is the time limit

moshu123 @ 11 Feb 2011 07:31 PM

@Admin

What is the time limit for this problem?

At least that can be shared.

i am getting a asymptotic

abhinavatul @ 27 Feb 2011 11:40 PM

i am getting a asymptotic time complexity of O(N2 S) where N is the number of players and S is the sum of all skils , but getting TLE , can this be due to the use of STL iterators ?? OR do i need to further reduce asymptotic time complexity ??? Please help

More than one solution can

narainbalaji @ 10 Mar 2011 12:07 AM

More than one solution can exist as pointed out by suresh

Oops my solution got

javasoul @ 18 Mar 2011 10:06 PM

Oops my solution got accepted...

Hi Guys,  One imp. test case

javasoul @ 18 Mar 2011 10:33 PM

Hi Guys,

 One imp. test case is,

N=100, and all nos are: 450

@Anil,    time limit is

javasoul @ 18 Mar 2011 11:10 PM

@Anil,

   time limit is O(N*S),

somebody please give me a

abhinavatul @ 11 Jun 2011 02:16 PM
somebody please give me a test case where my sol is failing , i have reduced my time complexity to O(N*S) , http://www.codechef.com/viewsolution/571364

@admin: the above explained

frankie619 @ 18 Jun 2011 09:08 PM
@admin: the above explained example is wrong eg in 2nd test case strength point is summing up to 27 32, bt here it is given 27 27, so i hope the code i submitted is correct . . . . hope u wud recheck it . .

http://www.cool-smileys.com/i

abhinavatul @ 20 Jun 2011 06:50 PM
http://www.cool-smileys.com/images/2066.gif

@admin when I run my program

omron2010 @ 4 Jul 2011 01:25 AM
@admin when I run my program I get TLE. If I throw an exception on testcase 99 it halts with an error after 5 seconds of running time. I've tested my solution on a testcase with T and N both 100. Each testcase runs in about 75ms. Can you please have a look and tell me what's wrong: http://www.codechef.com/viewsolution/590385

Are question actually in any

omron2010 @ 4 Jul 2011 10:09 PM
Are question actually in any way answered here? Or should we search for a little help/hint elsewhere. If so, where?

output given to fisrt input

cs1rangers @ 27 Aug 2011 04:33 PM
output given to fisrt input is wrong...190+200 !=3+90+200+100

Read the input specifications

anki028 @ 27 Aug 2011 07:07 PM
Read the input specifications again. 3 is the number of players and not the strength value of one of the players.

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 computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various 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 judge accepts solutions in over 35+ programming languages. Online programming was 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 competitions 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 programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

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. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

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