A10785 | Hanoi Factory
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line of the input contains a single integer $n$ ( $1<=n<=100000$ ) — 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.
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.
输出格式
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 $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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted