PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000041. Ba lô 2 (Knapsack 2)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ba lô 2 (Knapsack 2)
Knapsack 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You have items, where item has weight and value . The knapsack capacity can be very large, whereas individual values are comparatively small. Each item may be used at most once. Find the maximum attainable value without exceeding total weight .
Input
The first line contains and , followed by lines containing and .
Output
Print the maximum total value of the chosen items.
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , , .
- Subtask 2 (30%): , , , .
- Subtask 3 (50%): , , , .
Examples
Input
3 8
3 30
4 50
5 60
Output
90
Explanation
Choose items 1 and 3: weight and value . Taking only item 3 yields , so the optimal value is .