PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000463. Tham dự sự kiện có giới hạn (Maximum Number of Events That Can Be Attended II)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tham dự sự kiện có giới hạn (Maximum Number of Events That Can Be Attended II)
Maximum Number of Events That Can Be Attended II
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are events, each with start , end and reward for completing it. Select at most 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 2
1 2 4
3 4 3
2 3 1
Output
7
Explanation
Events 1 and 2 yield 7.
Example 2
Input
3 2
1 2 4
3 4 3
2 3 10
Output
10
Explanation
Event 3 yields 10 and overlaps the other two.
Example 3
Input
4 3
1 1 1
2 2 2
3 3 3
4 4 4
Output
9
Explanation
Choose the three highest rewards: 2,3,4.