~/algor $ cat problems/dp-loyihalar-foydasi
Maximum profit from projects
Medium
1000 ms
128 MB
56%
$n$ projects are offered: the $i$-th project lasts from day $s_{i}$ to day $e_{i}$ (both inclusive) and brings $p_{i}$ soums of profit. Only one project can be worked on per day, and a started project is carried out to the end. Which projects should be taken to make the total profit as large as possible? Print this profit.
Input
The first line contains a positive integer $n$. Each of the next $n$ lines contains three positive integers: $s_{i}$, $e_{i}$, $p_{i}$.
Output
One integer — the largest total profit.
Note
$1 \le n \le 10^{5}$
$1 \le s_{i} \le e_{i} \le 10^{9}$
$1 \le p_{i} \le 10^{9}$
Examples
Input #1
4 1 3 5 2 5 6 4 6 5 7 8 3
Output #1
13
Input #2
2 1 5 4 5 9 4
Output #2
4