Codeforces Round 401 (Div. 2)
E
Hanoi Factory
Codeforces
2000
原题
← D→
翻译中…

Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strange order so they had to create this new tower using already produced rings.

翻译中…

There are $*n*$ rings in factory's stock. The $*i*$-th ring has inner radius $*a*_{*i*}$, outer radius $*b*_{*i*}$ and height $*h*_{*i*}$. The goal is to select some subset of rings and arrange them such that the following conditions are satisfied:

翻译中…
  • Outer radiuses form a non-increasing sequence, i.e. one can put the $*j*$-th ring on the $*i*$-th ring only if $*b*_{*j*} ≤ *b*_{*i*}$.
  • Rings should not fall one into the the other. That means one can place ring $*j*$ on the ring $*i*$ only if $*b*_{*j*} > *a*_{*i*}$.
  • The total height of all rings used should be maximum possible.
翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($1 ≤ *n* ≤ 100 000$) — the number of rings in factory's stock.

翻译中…

The $*i*$-th of the next $*n*$ lines contains three integers $*a*_{*i*}$, $*b*_{*i*}$ and $*h*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*}, *h*_{*i*} ≤ 10^{9}$, $*b*_{*i*} > *a*_{*i*}$) — inner radius, outer radius and the height of the $*i*$-th ring respectively.

翻译中…

Output

翻译中…

Print one integer — the maximum height of the tower that can be obtained.

翻译中…

Note

翻译中…

In the first sample, the optimal solution is to take all the rings and put them on each other in order $3$, $2$, $1$.

翻译中…

In the second sample, one can put the ring $3$ on the ring $4$ and get the tower of height $3$, or put the ring $1$ on the ring $2$ and get the tower of height $4$.

翻译中…

样例

Input #1
3
1 5 1
2 6 2
3 7 3
Output #1
6
InputCopy OutputCopy
Input #2
4
1 2 1
1 3 3
4 6 2
5 7 1
Output #2
4
InputCopy OutputCopy
题目信息
题号
777E
时间限制
1 s
内存限制
256 MB
标签
暴力
数据结构
动态规划
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。