Angel, a good friend of yours, has a truck that can transport a maximum weight . He has objects at home, each with weight and value . He will depart, so he wants to pick the most valuable subset of objects with total weight no larger than . However, Angel does not like to compute optimal solutions. Can you help him?
Input consists of several cases with only integer numbers. Every case begins with and , followed by pairs , . Assume , , , and .
For every case, print three lines. On the first, print the largest possible total value. On the second, print the number of objects of the optimal subset. On the third, print in increasing order and separated by spaces the indices (starting at one) of the chosen objects. If there is more than one optimal solution, you can choose any one.
Author: Salvador Roura
Generation: 2026-01-25T11:25:05.453Z
© Jutge.org, 2006–2026.
https://jutge.org