PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000060. Ba lô và truy vết (Knapsack)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ba lô và truy vết (Knapsack)

Knapsack

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A knapsack has integer capacity CC, and there are nn items indexed from 00 to n−1n-1. Item ii has value viv_i and weight wiw_i. Select each item at most once, maximizing total value while keeping total weight at most CC. You must output the indices of an optimal selection. If multiple optimal selections exist, any one is accepted, and indices may appear in any order.

Input

The first line contains CC and nn. Then follow nn lines, each giving value viv_i first and weight wiw_i second.

Output

Print the number kk of selected items on the first line and then kk distinct indices in [0,n−1][0,n-1] on the next line (the second line may be empty for k=0k=0).

Subtasks

The independent scoring groups have the following complete constraints:

  • Subtask 1 (20%): 1≤C≤301\le C\le30, 1≤n≤121\le n\le12, 1≤wi,vi≤301\le w_i,v_i\le30.
  • Subtask 2 (30%): 1≤C≤3001\le C\le300, 1≤n≤1001\le n\le100, 1≤wi,vi≤5001\le w_i,v_i\le500.
  • Subtask 3 (50%): 1≤C≤20001\le C\le2000, 1≤n≤20001\le n\le2000, 1≤wi,vi≤100001\le w_i,v_i\le10000.

Examples

Input

5 3
1 5
10 5
100 5

Output

1
2

Explanation

All three items weigh 55, but the capacity is only 55. Exactly one item should be selected: zero-based index 22 has the largest value (100100). Print the count 11 followed by index 22.