PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000040. Ba lô 1 (Knapsack 1)
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ô 1 (Knapsack 1)
Knapsack 1
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Taro has distinct items numbered from to . Item has weight and value . His knapsack can carry total weight at most . Each item can be selected at most once, and choosing no item is allowed. Determine the greatest possible total value subject to the weight limit.
Input
The first line contains and . Each of the following lines contains and .
Output
Print one integer: the maximum total value.
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
Select items 1 and 3: their combined weight is , and total value is . Items 2 and 3 together weigh , which exceeds capacity. The optimum is .