CDC12_B - Basic Routines

no tags 

Ronny is arriving from the work and the terrible traffic he was on. He leaves the car keys and decides to go and lay down to think about the activities he must do. He soon realizes that some activities require more energy than others. Ronny has N activities planned, and each activity has a name and a value associated, which is the amount of energy Ronny will spend by doing this activity. In addition, Ronny recovers energy each time he finishes an activity. He recovers number of energy points equal to number activities he has completed. For example, if he has 80 points of energy and doing an activity X costs Y energy, then he will have 80−Y+1 energy points. If he then performs another activity with costing Z energy, he will have (80−Y +1)−Z+2 energy points. Ronny’s energy must never be lower than 0 points.

He realized that he may not be able to complete all the activities. You are required to write a program to help him choose an subset of activities that can be finished with the given amount energy. See output description for more details.

Input

The first line contains an integer T , number of test cases. Then, descriptions of T test cases. Each test case will begin with two integers N and E, denoting respectively the number of activities that Ronny has planned and Ronny’s initial energy. N lines will follow, each with a string A and an integer V , denoting the name of the activity and the value associated with it.

The data must be read from standard input.

Output

For each input case you must print two lines line. First must start with string "Scenario #i:", where i is the test case number (starting by 1). Next a space and the maximum number of activities Ronny can do. Second line must contain a list of activities sorted by name (order of execution may be different). There must be an space after each name.

If there are many possible solutions, output the subset that requires the least amount of energy. If there is still a tie, output the lexicographical smaller sequence of names.

The output must be written to standard output.

Input Output
2
5 80
CleanClothes 45
MakeFood 40
Shower 10
EatFood 20
WatchTv 5
4 80
Gaming 20
TVShow 30
ScoreSomeCoke 20
DrinkCoke 10
Scenario #1: 4
EatFood MakeFood Shower WatchTv
Scenario #2: 4
DrinkCoke Gaming ScoreSomeCoke TVShow


Constraints

 T ≤ 100

 1 ≤ N ≤ 100,000

 1 ≤ E ≤ 1,000,000

 1 ≤ |A| ≤ 100

 1 ≤ V ≤ 100

First case analysis:

Ronny can choose activities {1, 3, 4, 5} or {2, 3, 4, 5}. Doing the second set of activities costs him less energy, so that's the final answer.

News: Inserted all test cases from the original contest. Statement updated.


hide comments
[Rampage] Blue.Mary: 2016-09-13 10:27:18

The hints below is right. You MUST use int everywhere (including the place where long long should be used in the correct solution) in order to get AC. The judge output data is wrong.

Rishav Goyal: 2015-06-26 15:23:33

yes. there is some overflow problem.

RjlovesS: 2015-02-26 17:12:23

Truly a waste of time. Ya there is an issue on using long long and also be careful with the duplicates when trying to use map.

Last edit: 2015-02-26 17:17:02
Ivan Hendrajaya: 2013-02-05 02:24:52

The judge solution seems incorrect. The first problem, I must changed long long into int to get AC (I think the judge solution has an overflow issue). The second problem, incorrect solution (not clearing vector that contain unused activity) also get AC. CMIIW

<b>Setter says:</b> There is no overflow warning nor whatsoever in this problem, you can read the constraints to note it (I myself checked all the input data and I can say it is OK). For the second issue, I will check this and thank you for noticing :)

Can you check what is the judge solution output for this test case?
1
100000 1000000
a 1 (100000 times)
My AC solution (with int for energy) gives 65522, but the correct answer is 100000 right? I think that's why my other solution (with long long for energy) getting WA here.

Last edit: 2013-03-04 16:52:28
Suraj D: 2012-11-29 09:35:37

He Recovers only after he FINISHES an activity. :)


Added by:Venezuelan Programming League
Date:2012-10-27
Time limit:0.209s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem used for UCV-CEIDEC contest.