A9876 | Gerald and Path
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The Geraldionians love to walk on this path at any time, so the mayor of the city asked the Herald to illuminate this path with a few spotlights. The spotlights have already been delivered to certain places and Gerald will not be able to move them. Each spotlight illuminates a specific segment of the path of the given length, one end of the segment is the location of the spotlight, and it can be directed so that it covers the segment to the south or to the north of spotlight.
The trail contains a monument to the mayor of the island, and although you can walk in either directions from the monument, no spotlight is south of the monument.
You are given the positions of the spotlights and their power. Help Gerald direct all the spotlights so that the total length of the illuminated part of the path is as much as possible.
The trail contains a monument to the mayor of the island, and although you can walk in either directions from the monument, no spotlight is south of the monument.
You are given the positions of the spotlights and their power. Help Gerald direct all the spotlights so that the total length of the illuminated part of the path is as much as possible.
输入格式
The first line contains integer $n$ ( $1<=n<=100$ ) — the number of spotlights. Each of the $n$ lines contains two space-separated integers, $a_{i}$ and $l_{i}$ ( $0<=a_{i}<=10^{8}$ , $1<=l_{i}<=10^{8}$ ). Number $a_{i}$ shows how much further the $i$ -th spotlight to the north, and number $l_{i}$ shows the length of the segment it illuminates.
It is guaranteed that all the $a_{i}$ 's are distinct.
It is guaranteed that all the $a_{i}$ 's are distinct.
输出格式
Print a single integer — the maximum total length of the illuminated part of the path.
输入输出样例
输入 #1
3 1 1 2 2 3 3
输出 #1
5
输入 #2
4 1 2 3 3 4 3 6 2
输出 #2
9
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted