A11606 | Run For Your Prize
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show $n$ prizes are located on a straight line. $i$ -th prize is located at position $a_{i}$ . Positions of all prizes are distinct. You start at position $1$ , your friend — at position $10^{6}$ (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly $1$ second to move from position $x$ to position $x+1$ or $x-1$ , both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
At the start of the show $n$ prizes are located on a straight line. $i$ -th prize is located at position $a_{i}$ . Positions of all prizes are distinct. You start at position $1$ , your friend — at position $10^{6}$ (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly $1$ second to move from position $x$ to position $x+1$ or $x-1$ , both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
输入格式
The first line contains one integer $n$ ( $1<=n<=10^{5}$ ) — the number of prizes.
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $2<=a_{i}<=10^{6}-1$ ) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $2<=a_{i}<=10^{6}-1$ ) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
输出格式
Print one integer — the minimum number of seconds it will take to collect all prizes.
输入输出样例
输入 #1
3 2 3 9
输出 #1
8
输入 #2
2 2 999995
输出 #2
5
In the first example you take all the prizes: take the first at $1$ , the second at $2$ and the third at $8$ .
In the second example you take the first prize in $1$ second and your friend takes the other in $5$ seconds, you do this simultaneously, so the total time is $5$ .
In the second example you take the first prize in $1$ second and your friend takes the other in $5$ seconds, you do this simultaneously, so the total time is $5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted