MENU - Menu


Alfred wants to plan what to cook in the next days. He can cook various dishes. For each dish the costs of the ingredients and the benefit value is known. If a dish is cooked the second time in a row, the benefit value for the second time is 50 percent of the benefit value of first time, if it is prepared for the third or higher time in a row, the benefit value is 0. For example cooking a dish with benefit value v three times in a row leads to a total benefit value of 1.5*v.
Help him to build the menu which maximizes the benefit value under the constraint that his budget is not exceeded.

Input

The input consists of several test cases. Each test case begins with 3 integers in a line: The number of days k (1 ≤ k ≤ 21) Alfred wants to plan for, the number of dishes n (1 ≤ n ≤ 50) he can cook and his budget m (0 ≤ m ≤ 100). The following n lines describe the dishes Alfred can cook. The i-th line contains two integers: the costs c (1 ≤ c ≤ 50) and the benefit value v (1 ≤ v ≤ 10000) of the i-th dish.
The end of the input is signaled by a test case with k = n = m = 0. You don't need to process this test case.

Output

For each output, print the maximum benefit value reachable with 1 digit after the decimal point. Then print k integers with i-th integer being the number of the dish to cook on day i. Dishes are numbered from 1 to n. Print at least one space or new line character after each integer.
If there are several possible menus reaching the maximum benefit value, select the one with minimum costs, if there are several with minimum costs, you can print any of them.
If every menu exceeds the budget, print only the benefit value of 0.

Example

Input:
2 1 5
3 5
3 5 20
2 5
18 6
1 1
3 3
2 3
0 0 0

Output:
0.0

13.0
1 5 1 

hide comments
besher massri: 2014-08-02 19:31:08

nice problem ... AC in the first GO :)

Aradhya: 2013-05-28 20:56:22

took my whole day ! :D

uberness132: 2012-11-11 04:59:43

@Adrian, is my algorithm too slow? What's the max test # of cases per input?

Adrian Kuegel: 2012-09-20 12:31:01

Thanks, but GCPC11F and GCPC11J are actually from Tobias Werth (it is also mentioned in the "Resource" section). If you want to take a look at my problems which I have posed in different contests, I have put up a list here: http://www.uni-ulm.de/en/in/institute-of-theoretical-computer-science/m/kuegel/aufgaben.html

Haidar Abboud: 2012-09-09 19:08:58

Adrian Kuegel , your problems are ultra interesting for those doing algorithms just for fun(not as part of their study field or work)
Other Ones include : GCPC11F , GCPC11J


Added by:Adrian Kuegel
Date:2005-07-04
Time limit:0.702s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:own problem