PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000467. Hai sự kiện không giao nhau tốt nhất (Two Best Non-Overlapping Events)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hai sự kiện không giao nhau tốt nhất (Two Best Non-Overlapping Events)
Two Best Non-Overlapping Events
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are events, each with start , end and reward for completing it. Select at most two events without overlap. Both endpoints are inclusive, so the next start must be strictly greater than the previous end. Maximize the total reward.
Input
The first line contains . The next lines each contain three integers .
Output
Print the largest total reward.
Subtasks
- Subtask 1 (20 points): ; ; ().
- Subtask 2 (30 points): ; ; ().
- Subtask 3 (50 points): ; ; ().
Examples
Example 1
Input
3
1 3 2
4 5 2
2 4 3
Output
4
Explanation
Events 1 and 2 yield 4; event 3 overlaps both.
Example 2
Input
3
1 3 2
4 5 2
1 5 5
Output
5
Explanation
Event 3 alone is better than 2+2.
Example 3
Input
3
1 5 3
1 5 1
6 6 5
Output
8
Explanation
Events 1 and 3 yield 8.