B. Run For Your Prize
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (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?

Input

The first line contains one integer n (1 ≤ n ≤ 105) — the number of prizes.

The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 106 - 1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.

Output

Print one integer — the minimum number of seconds it will take to collect all prizes.

Examples
input

Copy
3
2 3 9
output
8
input

Copy
2
2 999995
output
5
Note

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.

题目大意:你在1位置,朋友在10^6位置,每次花1单位时间挪动1格,有n个礼物,问最少花多少时间拿到所有礼物.

分析:这题目水的......求一下礼物距你和朋友的距离,取个min,然后排序,取最大的就好了.

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include <cmath> using namespace std; typedef long long LL; int n,a[]; int main()
{
scanf("%d",&n);
for (int i = ; i <= n; i++)
{
scanf("%d",&a[i]);
a[i] = min(a[i] - , - a[i]);
}
sort(a + ,a + + n);
printf("%d\n",a[n]); return ;
}

Codeforces 938.B Run For Your Prize的更多相关文章

  1. Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)

    题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...

  2. Codeforces 938.D Buy a Ticket

    D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. Codeforces 938.C Constructing Tests

    C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. Codeforces 938.A Word Correction

    A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces 938 正方形方格最多0/1 足球赛dijkstra建图

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  6. CF938B Run For Your Prize 题解

    Content 有两个人,一个在 \(1\) 处,一个在 \(10^6\) 处,在他们之间有 \(n\) 个奖品,第 \(i\) 个奖品在 \(a_i\) 处.一开始在 \(1\) 处的人每秒可向右移 ...

  7. Educational Codeforces Round 38 (Rated for Div. 2)

    这场打了小号 A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input sta ...

  8. 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解

    [比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B  Run for your prize[贪心] ...

  9. Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp

    B. Wizards and Huge Prize Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

随机推荐

  1. git分布式版本控制系统常用的操作

    Git是一个版本控制系统,用来追踪计算机文件的变化的工具,也是一个供多人使用的协同工具.它是一个分布式的版本控制系统,本文将简单介绍如何使用.简单来说,就是你要和你的伙伴一起完成一项任务,但是你们要互 ...

  2. js如何获得系统时间年月日时分秒

    javascript 自带有个对象(构造函数),Date().下面是代码: 回答一: var now = new Date();  var nowTime = now.toLocaleString() ...

  3. PHP Socket服务器搭建和测试

    1.socket服务器搭建思路 1) 目的:理解socket服务器工作机制 2) 思路:创建socket -> 把socket加入连接池 -> 处理接收信息 -> 握手动作 -> ...

  4. [Bzoj3611]大工程(虚树+DP)

    Description 题目链接 Solution 在虚树上跑DP即可 关于虚树的建立,是维护一个最右链的过程 关键代码如下: sort(A+1,A+k+1,cmp);//按dfs序排序 s[top= ...

  5. 在庫購買管理(MM)

    ■購買管理■ [購買依頼]ME51N: 登録ME52N: 変更ME53N: 照会 [購買発注]ME21N: 登録ME22N: 変更ME23N: 照会 [見積依頼]ME41: 登録ME42: 変更ME4 ...

  6. 零基础学html第一天

    html:超文本标记语言 unicode(UTF-8):万国码 <...>:标记标签   :空格 <br>:换行 <hr>:水平线 <p></p& ...

  7. 4-linux基本命令

    1. cd命令 cd 回当前用户 家目录   cd /home  进入home目录 (绝对路径)   (相对路径)   cd –  上一目录和当前目录来回切换(主要用于返回上一目录)   cd .   ...

  8. CodeForces 873D Merge Sort 构造 分治

    题意 给出一个归并排序的算法\(mergesort\),如果对于当前区间\([l, r)\)是有序的,则函数直接返回. 否则会分别调用\(mergesort(l, mid)\)和\(mergesort ...

  9. Android stadio Switch repository Android stadio切换仓库

    Android stadio 有时候,有很多module. 这些module 都有自己的仓库.也就是不在一块.那么,Android stadio 默认管理的就是根git. 如图,画对号的就是默认的. ...

  10. Trident学习笔记(二)

    aggregator ------------------ 聚合动作:聚合操作可以是基于batch.stream.partiton [聚合方式-分区聚合] partitionAggregate 分区聚 ...