Weighted Interval Scheduling
You are given n jobs. Job i occupies the half-open time interval [s_i, e_i) and pays a profit of p_i if it is done.
A single machine can work on at most one job at a time, so a chosen set of jobs must be pairwise non-overlapping. Because the intervals are half-open, two jobs that only touch (one ends at the exact moment the other starts, e_i = s_j) are compatible.
Choose a set of pairwise non-overlapping jobs with the largest total profit. The empty set is allowed.
Input
The first line contains an integer n (1 ≤ n ≤ 2·10^5), the number of jobs.
Each of the next n lines contains three integers s_i, e_i, p_i (0 ≤ s_i < e_i ≤ 10^9, 1 ≤ p_i ≤ 10^9): the start, the end and the profit of job i. Several jobs may have identical intervals.
Output
Print one integer: the maximum total profit. It may not fit in a 32-bit integer.
Notes
In the first example, the best choice is the jobs [1, 3), [3, 6) and [6, 9) with profit 5 + 6 + 4 = 15. They touch at times 3 and 6, which is allowed. The single job [2, 8) pays only 12.
In the second example, every job overlaps with every other, so only one job can be taken. The most profitable one pays 10.