Optimal choice P65534


Statement
 

pdf   zip

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.

Public test cases
  • Input

    10000 3
    5000 20
    8000 27
    4000 10
    
    10000 3
    5000 20
    8000 100
    4000 10
    
    1000000 2
    900000 10
    100000 20
    
    1000000000000 10
    100000000000 1
    200000000007 2
    300000000000 3
    400000000001 4
    500000000003 5
    100000000000 1
    200000000000 2
    300000000000 3
    400000000005 4
    500000000000 5
    

    Output

    30
    2
    1 3
    100
    1
    2
    30
    2
    1 2
    10
    3
    7 8 10
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++