PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000023. Công việc và thời hạn (Tasks and Deadlines)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Công việc và thời hạn (Tasks and Deadlines)
Tasks and Deadlines
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
There are tasks. Task has duration and deadline . If completed at time , its reward is . Tasks are processed one by one from time . Maximize the total reward.
Input
The first line contains . Each of the next lines contains .
Output
Print the maximum total reward.
Constraints
- .
- for .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
3
6 10
8 15
5 12
Output
2
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.