#CT00000055. Lịch hoạt động (Activity Schedule)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Lịch hoạt động (Activity Schedule)
Activity Schedule
Version: Phuoc Hung OJ Extended
Problem Statement
A festival offers activities, numbered from to in input order. Activity begins at time , ends at time , and awards points if attended in full.
The activity occupies the half-open interval : it includes its starting time but not its ending time . Selected activities must not overlap. If one activity ends exactly when another begins, both may be chosen. Every selected activity must be attended in full.
A student may choose at most activities and need not choose exactly . Choosing no activity is allowed and gives a total score of . The score is the sum of over the selected activities.
Find the maximum achievable total score.
Input
- The first line contains two positive integers : the number of activities and the maximum number of activities that may be selected.
- Each of the next lines contains three integers : the starting time, ending time, and score of activity . The activities are not necessarily listed in chronological order.
Output
Print one integer: the maximum total score obtainable by selecting at most pairwise non-overlapping activities.
Subtasks
The following general constraints apply to all subtasks: ; ; ; .
- Subtask 1 (30%): .
- Subtask 2 (30%): .
- Subtask 3 (40%): No additional restrictions beyond the general constraints.
Examples
Example 1
Input
4 2
1 3 5
3 5 6
2 6 9
5 7 4
Output
11
Explanation
Activity occupies and is worth points; activity occupies and is worth points. The first ends exactly when the second begins, so both may be selected, giving points with activities.
Another compatible pair, activities and , gives points. Activity gives points but overlaps the other activities it could be paired with to exceed . Hence the maximum is .
Example 2
Input
3 1
1 4 3
2 3 5
3 8 4
Output
5
Explanation
Since , at most one activity may be chosen. The three activities award points, respectively. Choosing activity yields the maximum score of .
Example 3
Input
4 3
1 2 4
2 3 5
3 4 6
1 4 100
Output
100
Explanation
The first three activities occupy , , and ; they can all be attended consecutively, giving points. Activity occupies and overlaps each of those three, so none may be selected together with it. Choosing activity alone yields points, greater than . The answer is .
Liên quan
Trong các cuộc thi sau: