atcoder#DPD. Knapsack 1
Knapsack 1
Score : points
Problem Statement
There are items, numbered . For each (), Item has a weight of and a value of .
Taro has decided to choose some of the items and carry them home in a knapsack. The capacity of the knapsack is , which means that the sum of the weights of items taken must be at most .
Find the maximum possible sum of the values of items that Taro takes home.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible sum of the values of items that Taro takes home.
3 8
3 30
4 50
5 60
90
Items and should be taken. Then, the sum of the weights is , and the sum of the values is .
5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
5000000000
The answer may not fit into a 32-bit integer type.
6 15
6 5
5 6
6 4
6 6
3 5
7 2
17
Items and should be taken. Then, the sum of the weights is , and the sum of the values is .