1751. Maximum Number of Events That Can Be Attended II Hard

@problem@discussion
#Array#Binary Search#Dynamic Programming



1/**
2 * [1751] Maximum Number of Events That Can Be Attended II
3 *
4 * You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The i^th event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also given an integer k which represents the maximum number of events you can attend.
5 * You can only attend one event at a time. If you choose to attend an event, you must attend the entire event. Note that the end day is inclusive: that is, you cannot attend two events where one of them starts and the other ends on the same day.
6 * Return the maximum sum of values that you can receive by attending events.
7 *  
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-60048-pm.png" style="width: 400px; height: 103px;" />
10 * 
11 * Input: events = [[1,2,4],[3,4,3],[2,3,1]], k = 2
12 * Output: 7
13 * Explanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-60150-pm.png" style="width: 400px; height: 103px;" />
16 * 
17 * Input: events = [[1,2,4],[3,4,3],[2,3,10]], k = 2
18 * Output: 10
19 * Explanation: Choose event 2 for a total value of 10.
20 * Notice that you cannot attend any other event as they overlap, and that you do not have to attend k events.
21 * Example 3:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-60703-pm.png" style="width: 400px; height: 126px;" />
23 * 
24 * Input: events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3
25 * Output: 9
26 * Explanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three.
27 *  
28 * Constraints:
29 * 
30 * 	1 <= k <= events.length
31 * 	1 <= k * events.length <= 10^6
32 * 	1 <= startDayi <= endDayi <= 10^9
33 * 	1 <= valuei <= 10^6
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii/
39// discuss: https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn max_value(events: Vec<Vec<i32>>, k: i32) -> i32 {
45        0
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_1751() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.