← 返回 snowflake 的题目列表Maximum Number of Events That Can Be Attended II
类型:online_judge
Problem: Maximum Number of Events That Can Be Attended II
You are given a 2D array events, where:
events[i] = [startDay_i, endDay_i, value_i]
The i-th event starts at startDay_i and ends at endDay_i. If you attend this event completely, you receive value_i.
You are also given an integer k, which represents the maximum number of events you can attend.
Rules:
You can only attend one event at a time.
If you choose to attend an event, you must attend the entire event.
The endDay is inclusive. This means if one event ends on day d and another starts on day d, you cannot attend both.
Two events are compatible only if the later event's startDay is strictly greater than the earlier event's endDay.
Return the maximum total value you can receive by attending at most k events.
Input Format
n k
events[0][0] events[0][1] events[0][2]
events[1][0] events[1][1] events[1][2]
...
events[n-1][0] events[n-1][1] events[n-1][2]
where n is the number of events.
Output Format
maximum_value
Constraints
1 <= n <= 10^5
1 <= k <= n
1 <= k * n <= 10^6
1 <= startDay_i <= endDay_i <= 10^9
1 <= value_i <= 10^6
Example
Input:
3 2
1 2 4
3 4 3
2 3 1
Output:
7
Explanation: Attend events [1,2,4] and [3,4,3], with total value 4 + 3 = 7.
Example
Input
3 2
1 2 4
3 4 3
2 3 1
Output
7