PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000094. Xây tháp (Tower)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xây tháp (Tower)
Tower
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are distinct blocks. Block has weight , strength , and value . Choose any subset and arrange it vertically in any order. A tower is valid when, for every selected block, the total weight of all blocks above it is at most its strength . Find the maximum total value of a valid tower. Choosing no blocks is allowed.
Input
The first line contains . Each of the next lines contains .
Output
Print the maximum total value of a valid tower.
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , .
- Subtask 2 (30%): , , .
- Subtask 3 (50%): , , .
Examples
Input
3
2 2 20
2 1 30
3 1 40
Output
50
Explanation
Place block 2 on top of block 1. Block 1 supports weight , equal to its strength. Their total value is , which is optimal.