A10029 | Bulbo
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Bananistan is a beautiful banana republic. Beautiful women in beautiful dresses. Beautiful statues of beautiful warlords. Beautiful stars in beautiful nights.
In Bananistan people play this crazy game – Bulbo. There’s an array of bulbs and player at the position, which represents one of the bulbs. The distance between two neighboring bulbs is 1. Before each turn player can change his position with cost $|pos_{new}-pos_{old}|$ . After that, a contiguous set of bulbs lights-up and player pays the cost that’s equal to the distance to the closest shining bulb. Then, all bulbs go dark again. The goal is to minimize your summed cost. I tell you, Bananistanians are spending their nights playing with bulbs.
Banana day is approaching, and you are hired to play the most beautiful Bulbo game ever. A huge array of bulbs is installed, and you know your initial position and all the light-ups in advance. You need to play the ideal game and impress Bananistanians, and their families.
In Bananistan people play this crazy game – Bulbo. There’s an array of bulbs and player at the position, which represents one of the bulbs. The distance between two neighboring bulbs is 1. Before each turn player can change his position with cost $|pos_{new}-pos_{old}|$ . After that, a contiguous set of bulbs lights-up and player pays the cost that’s equal to the distance to the closest shining bulb. Then, all bulbs go dark again. The goal is to minimize your summed cost. I tell you, Bananistanians are spending their nights playing with bulbs.
Banana day is approaching, and you are hired to play the most beautiful Bulbo game ever. A huge array of bulbs is installed, and you know your initial position and all the light-ups in advance. You need to play the ideal game and impress Bananistanians, and their families.
输入格式
The first line contains number of turns $n$ and initial position $x$ . Next $n$ lines contain two numbers $l_{start}$ and $l_{end}$ , which represent that all bulbs from interval $[l_{start},l_{end}]$ are shining this turn.
- $1<=n<=5000$
- $1<=x<=10^{9}$
- $1<=l_{start}<=l_{end}<=10^{9}$
- $1<=n<=5000$
- $1<=x<=10^{9}$
- $1<=l_{start}<=l_{end}<=10^{9}$
输出格式
Output should contain a single number which represents the best result (minimum cost) that could be obtained by playing this Bulbo game.
输入输出样例
输入 #1
5 4 2 7 9 16 8 10 9 17 1 6
输出 #1
8
Before 1. turn move to position 5
Before 2. turn move to position 9
Before 5. turn move to position 8
Before 2. turn move to position 9
Before 5. turn move to position 8
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted