The Time Traveler's Paradox
A time traveler must visit historical events without causing paradoxes. Each event has a start time, end time, and importance value.
The traveler cannot attend overlapping events (events that share any time in common). However, events that share only an endpoint (one ends exactly when another starts) do NOT overlap.
Find the maximum total importance the traveler can achieve by selecting non-overlapping events.
Note: This is similar to the weighted job scheduling problem.
Input Format
The first line contains an integer n, the number of events. The next n lines each contain three integers: start, end, and importance.
Output Format
Print a single integer representing the maximum total importance achievable.
Examples
Example 1
Example 2
Constraints
•
1 ≤ n ≤ 1000
•
1 ≤ start < end ≤ 10^6
•
1 ≤ importance ≤ 10^6
Code
Case 1
Case 2
