Tap here to switch tabs
Problem
Submissions

Problem: Two Best Non-Overlapping Events

med
30 min
Try to solve the Two Best Non-Overlapping Events problem.

Statement

You are given a 22D integer array events where events[i] = [startTime_i, endTime_i, value_i]. The iextthi^{ ext{th}} event starts at startTime_i and ends at endTime_i, and attending this event yields a value of value_i.

You can choose at most 22 non overlapping events to attend such that the total sum of their values is maximized.

Return the maximum sum of values you can achieve.

Note: If you choose to attend 22 events, their active intervals cannot overlap. Specifically, if the first event ends at time tt, the second event must start at a time strictly greater than tt.

Constraints:

  • 2≤2 \leq events.length ≤105\leq 10^5

  • events[i].length =3= 3

  • 1≤1 \leq startTime_i ≤\leq endTime_i ≤109\leq 10^9

  • 1≤1 \leq value_i ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Two Best Non-Overlapping Events

med
30 min
Try to solve the Two Best Non-Overlapping Events problem.

Statement

You are given a 22D integer array events where events[i] = [startTime_i, endTime_i, value_i]. The iextthi^{ ext{th}} event starts at startTime_i and ends at endTime_i, and attending this event yields a value of value_i.

You can choose at most 22 non overlapping events to attend such that the total sum of their values is maximized.

Return the maximum sum of values you can achieve.

Note: If you choose to attend 22 events, their active intervals cannot overlap. Specifically, if the first event ends at time tt, the second event must start at a time strictly greater than tt.

Constraints:

  • 2≤2 \leq events.length ≤105\leq 10^5

  • events[i].length =3= 3

  • 1≤1 \leq startTime_i ≤\leq endTime_i ≤109\leq 10^9

  • 1≤1 \leq value_i ≤106\leq 10^6