java.lang.Object
g1701_1800.s1751_maximum_number_of_events_that_can_be_attended_ii.Solution

public class Solution extends Object
1751 - Maximum Number of Events That Can Be Attended II.<p>Hard</p> <p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code> and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will receive a value of <code>value<sub>i</sub></code>. You are also given an integer <code>k</code> which represents the maximum number of events you can attend.</p> <p>You can only attend one event at a time. If you choose to attend an event, you must attend the <strong>entire</strong> event. Note that the end day is <strong>inclusive</strong>: that is, you cannot attend two events where one of them starts and the other ends on the same day.</p> <p>Return <em>the <strong>maximum sum</strong> of values that you can receive by attending events.</em></p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-60048-pm.png" alt="" /></p> <p><strong>Input:</strong> events = [[1,2,4],[3,4,3],[2,3,1]], k = 2</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-60150-pm.png" alt="" /></p> <p><strong>Input:</strong> events = [[1,2,4],[3,4,3],[2,3,10]], k = 2</p> <p><strong>Output:</strong> 10</p> <p><strong>Explanation:</strong> Choose event 2 for a total value of 10. Notice that you cannot attend any other event as they overlap, and that you do <strong>not</strong> have to attend k events.</p> <p><strong>Example 3:</strong></p> <p><strong><img src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-60703-pm.png" alt="" /></strong></p> <p><strong>Input:</strong> events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3</p> <p><strong>Output:</strong> 9</p> <p><strong>Explanation:</strong> Although the events do not overlap, you can only attend 3 events. Pick the highest valued three.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= k <= events.length</code></li> <li><code>1 <= k * events.length <= 10<sup>6</sup></code></li> <li><code>1 <= startDay<sub>i</sub> <= endDay<sub>i</sub> <= 10<sup>9</sup></code></li> <li><code>1 <= value<sub>i</sub> <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxValue

      public int maxValue(int[][] events, int k)