#QHD0000060. Ba lô và truy vết (Knapsack)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ba lô và truy vết (Knapsack)
Knapsack
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A knapsack has integer capacity , and there are items indexed from to . Item has value and weight . Select each item at most once, maximizing total value while keeping total weight at most . 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 and . Then follow lines, each giving value first and weight second.
Output
Print the number of selected items on the first line and then distinct indices in on the next line (the second line may be empty for ).
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , .
- Subtask 2 (30%): , , .
- Subtask 3 (50%): , , .
Examples
Input
5 3
1 5
10 5
100 5
Output
1
2
Explanation
All three items weigh , but the capacity is only . Exactly one item should be selected: zero-based index has the largest value (). Print the count followed by index .