

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
個の品物があります。 品物には と番号が振られています。 各 () について、品物 の重さは で、価値は です。
太郎君は、 個の品物のうちいくつかを選び、ナップサックに入れて持ち帰ることにしました。 ナップサックの容量は であり、持ち帰る品物の重さの総和は 以下でなければなりません。
太郎君が持ち帰る品物の価値の総和の最大値を求めてください。
制約
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
出力
太郎君が持ち帰る品物の価値の総和の最大値を出力せよ。
入力例 1Copy
3 8 3 30 4 50 5 60
出力例 1Copy
90
品物 を選べばよいです。 すると、重さの総和は となり、価値の総和は となります。
入力例 2Copy
1 1000000000 1000000000 10
出力例 2Copy
10
入力例 3Copy
6 15 6 5 5 6 6 4 6 6 3 5 7 2
出力例 3Copy
17
品物 を選べばよいです。 すると、重さの総和は となり、価値の総和は となります。
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.
Sample Input 1Copy
3 8 3 30 4 50 5 60
Sample Output 1Copy
90
Items and should be taken. Then, the sum of the weights is , and the sum of the values is .
Sample Input 2Copy
1 1000000000 1000000000 10
Sample Output 2Copy
10
Sample Input 3Copy
6 15 6 5 5 6 6 4 6 6 3 5 7 2
Sample Output 3Copy
17
Items and should be taken. Then, the sum of the weights is , and the sum of the values is .