Optimal choice

Angel, a good friend of yours, has a truck that can transport a maximum weight WW. He has nn objects at home, each with weight wiw_i and value viv_i. He will depart, so he wants to pick the most valuable subset of objects with total weight no larger than WW. However, Angel does not like to compute optimal solutions. Can you help him?

Input

Input consists of several cases with only integer numbers. Every case begins with WW and nn, followed by nn pairs wiw_i, viv_i. Assume 1W10121 \le W \le 10^{12}, 1n1001 \le n \le 100, 1wiW1 \le w_i \le W, and 1vi1001 \le v_i \le 100.

Output

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.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:25:05.453Z

© Jutge.org, 2006–2026.
https://jutge.org