CF777E.Hanoi Factory

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn rings in factory's stock. The ii -th ring has inner radius aia_{i} , outer radius bib_{i} and height hih_{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 jj -th ring on the ii -th ring only if bj<=bib_{j}<=b_{i} .
  • Rings should not fall one into the the other. That means one can place ring jj on the ring ii only if bj>aib_{j}>a_{i} .
  • The total height of all rings used should be maximum possible.

输入格式

The first line of the input contains a single integer nn ( 1<=n<=1000001<=n<=100000 ) — the number of rings in factory's stock.

The ii -th of the next nn lines contains three integers aia_{i} , bib_{i} and hih_{i} ( 1<=ai,bi,hi<=1091<=a_{i},b_{i},h_{i}<=10^{9} , bi>aib_{i}>a_{i} ) — inner radius, outer radius and the height of the ii -th ring respectively.

输出格式

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

输入输出样例

  • 输入#1

    3
    1 5 1
    2 6 2
    3 7 3
    

    输出#1

    6
    
  • 输入#2

    4
    1 2 1
    1 3 3
    4 6 2
    5 7 1
    

    输出#2

    4
    

说明/提示

In the first sample, the optimal solution is to take all the rings and put them on each other in order 33 , 22 , 11 .

In the second sample, one can put the ring 33 on the ring 44 and get the tower of height 33 , or put the ring 11 on the ring 22 and get the tower of height 44 .

首页