|
|||||||||||||||||
|
SPOJ time: 2012-05-26 13:51:55 |
Another Knapsack ProblemProblem code: HS08AKP
Given 1 < n < 100 000 items, select some of them in such a way that the total weight of the selected items is at most S (1 < S < 1 000 000 000). For each item i you are given its weight 0 < mi < S and its value 0 <= vi < 1000. The larger the value of selected items, the better. Can you obtain the optimal solution? InputFirst two positive integers, S and n. Then n lines follows. In the i-th line there are exactly two numbers, denoting the mass and value of the i-th item, respectively. OutputIn the first line output k - the number of items to be taken. Next, output their numbers with respect to the order given by the input. ScoringThe score awarded to your program for a given test is computed as max{0, Vp - V}, where Vp is your program score, and V is a reference value (the result obtained by greedy approximation algorithm minus 10). The overall score of the program is the sum of scores obtained for the correctly solved tests. The number of points given in the ranking is scaled so that it is equal to 10 for the registered contestant whose solution has the highest score, and proportionally less for all solutions with lower scores. ExampleInput:
4 5
1 8
2 4
3 0
1 5
2 3
Output:
2
1 4
Scoring:
As V=7, the above solution scores max{0, 13 - 7} = 6 points.
Input data sizesApproximate test data sizes are given below. t n l 1 72100 2s 2 40000 2s 3 4000 2s 4 94100 2s 5 9000 2s t - testcase number n - the number of items l - time limit Please noteSubmissions will be visible to the submitting contestant, only, and tested on the full set of test cases.
|
||||||||||||||||
| |||||||||||||||||