TopCoder

User's AC Ratio

100.0% (5/5)

Submission's AC Ratio

41.2% (7/17)

Tags

Description

有 $N$ 個物品編號 $1 \sim N$,第 $i$ 個物品的重量和價值分別是 $w_i$ 和 $v_i$。學姐打算從這 $N$ 個物品選其中一些帶走,但她只有大小為 $W$ 的背包,也就是說她選擇的物品總重不能超過 $W$。請問背包能容納的物品的總價值最大是多少?

Input Format

輸入第一行有兩個正整數 $N$ 和 $W$。接下來 $N$ 行,每行都有兩個正整數,其中的第 $i$ 行的兩個正整數分別是 $w_i$, $v_i$。這些變數都對應到題目的變數。

  • $1 \le N \le 100$
  • $1 \le W \le 10^ {5}$
  • $1 \le w_i \le W$
  • $1 \le v_i \le 10^ {9}$

Output Format

輸出一個正整數,代表背包能容納的物品的總價值最大是多少。

Sample Input 1

3 8
3 30
4 50
5 60

Sample Output 1

90

Sample Input 2

5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 2

5000000000

Sample Input 3

6 15
6 5
5 6
6 4
6 6
3 5
7 2

Sample Output 3

17

Hints

Problem Source

AtCoder

Subtasks

No. Testdata Range Constraints Score
1 0~2 範例測資 0
2 0~25 無額外限制 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 524288 65536 1 2
1 1000 524288 65536 1 2
2 1000 524288 65536 1 2
3 1000 524288 65536 2
4 1000 524288 65536 2
5 1000 524288 65536 2
6 1000 524288 65536 2
7 1000 524288 65536 2
8 1000 524288 65536 2
9 1000 524288 65536 2
10 1000 524288 65536 2
11 1000 524288 65536 2
12 1000 524288 65536 2
13 1000 524288 65536 2
14 1000 524288 65536 2
15 1000 524288 65536 2
16 1000 524288 65536 2
17 1000 524288 65536 2
18 1000 524288 65536 2
19 1000 524288 65536 2
20 1000 524288 65536 2
21 1000 524288 65536 2
22 1000 524288 65536 2
23 1000 524288 65536 2
24 1000 524288 65536 2
25 1000 524288 65536 2