zoukankan      html  css  js  c++  java
  • E. Hanoi Factory

    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 ai, outer radius bi and height hi. 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 bj ≤ bi.
    • Rings should not fall one into the the other. That means one can place ring j on the ring i only if bj > ai.
    • 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 ai, bi and hi (1 ≤ ai, bi, hi ≤ 109, bi > ai) — 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.

    Examples
    Input
    3
    1 5 1
    2 6 2
    3 7 3
    Output
    6
    Input
    4
    1 2 1
    1 3 3
    4 6 2
    5 7 1
    Output
    4
    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.

    好了现在的我们假设我们知道的图形的形状是这个样子的,OK接下来我们好好的分析问题,因为题意是要求按照outer radius 的no-increasing

    so : 我们可以把outer radius 排序,然后发现这个问题真的是水题啊 。。。。

    真的是菜逼啊,竟然把题意看错了,把这个问题真的是想复杂了,这题是真的水啊、

    不得不承认我真的是菜逼啊,这题都能看错。 竟然用有限队列写了一发wa,然后发现这个问题是用stack来做的。

  • 相关阅读:
    Redpine的Lite-Fi解决方案获Wi-Fi CERTIFIED认证
    植物园偶遇一直喵
    美食篇
    端午节路过南站
    黄山云海
    一品黄山 天高云淡
    黄山的日出日落
    宏村,寻找你的前世今生
    git把本地文件上传到github上的步骤
    一张照片一个故事
  • 原文地址:https://www.cnblogs.com/Heilce/p/6480573.html
Copyright © 2011-2022 走看看