PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000070. Kỳ nghỉ hè (Summer Vacation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kỳ nghỉ hè (Summer Vacation)
Summer Vacation
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are one-time jobs. If job is performed on a day, it pays reward exactly days later. You may start today, perform at most one job per day, and cannot repeat jobs. Maximize the rewards received no later than days from today.
Input
The first line contains . Each of the next lines contains .
Output
Print the maximum reward received by the deadline.
Subtasks
- Subtask 1 (20 points): ; ; , for all .
- Subtask 2 (30 points): ; ; , for all .
- Subtask 3 (50 points): ; ; , for all .
Examples
Input
3 4
4 3
4 1
2 2
Output
5
Explanation
Do job today for reward received after days, then job tomorrow for reward received three days from today. Both pay within the -day deadline, giving total reward .