#1751
Maximum Number of Events That Can Be Attended II
expert · 1100 · lc hard +32 · verified · 63.6% accepted · 2,547 likes · top 66%
Description
You are given events[i] = [startDayi, endDayi, valuei] and an integer k. Attend at most k non-overlapping events (no sharing of start or end days) in their entirety. Return the maximum sum of values.
Example 1:
Input: events = [[1,2,4],[3,4,3],[2,3,1]], k = 2
Output: 7
Explanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.
Example 2:
Input: events = [[1,2,4],[3,4,3],[2,3,10]], k = 2
Output: 10
Explanation: Choose event 2 for a total value of 10.
Notice that you cannot attend any other event as they overlap, and that you do not have to attend k events.
Example 3:
Input: events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3
Output: 9
Explanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three.
Code
1
2
3