CF938B.Run For Your Prize

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You and your friend are participating in a TV show "Run For Your Prize".

At the start of the show nn prizes are located on a straight line. ii -th prize is located at position aia_{i} . Positions of all prizes are distinct. You start at position 11 , your friend — at position 10610^{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 11 second to move from position xx to position x+1x+1 or x1x-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 nn ( 1<=n<=1051<=n<=10^{5} ) — the number of prizes.

The second line contains nn integers a1a_{1} , a2a_{2} , ..., ana_{n} ( 2<=ai<=10612<=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 11 , the second at 22 and the third at 88 .

In the second example you take the first prize in 11 second and your friend takes the other in 55 seconds, you do this simultaneously, so the total time is 55 .

首页