• Educational Codeforces Round 38 (Rated for Div. 2) B. Run For Your Prize


    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
    Copy
    8
    input
    Copy
    2
    2 999995
    output
    Copy
    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 #include <algorithm>
     2 #include <stack>
     3 #include <istream>
     4 #include <stdio.h>
     5 #include <map>
     6 #include <math.h>
     7 #include <vector>
     8 #include <iostream>
     9 #include <queue>
    10 #include <string.h>
    11 #include <set>
    12 #include <cstdio>
    13 #define FR(i,n) for(int i=0;i<n;i++)
    14 #define MAX 2005
    15 #define mkp pair <int,int>
    16 using namespace std;
    17 //#pragma comment(linker, "/STACK:10240000000,10240000000")
    18 const int maxn = 1e5+50;
    19 typedef long long ll;
    20 const int  inf = 0x3fffff;
    21 void read(int  &x) {
    22     char ch; bool flag = 0;
    23     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
    24     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
    25     x *= 1 - 2 * flag;
    26 }
    27 
    28 int arr[maxn];
    29 int main() {
    30     int n;
    31     read(n);
    32     for(int i=0;i<n;i++)read(arr[i]);
    33     sort(arr,arr+n);
    34     int ans = 0;
    35     for(int i=0;i<n;i++)
    36     {
    37         int tmp = min(arr[i]-1,1000000-arr[i]);
    38         ans=max(tmp,ans);
    39     }
    40     cout<<ans<<endl;
    41     return 0;
    42 }
    View Code
    我身后空无一人,我怎敢倒下
  • 相关阅读:
    Shell中调用、引用、包含另一个脚本文件的三种方法
    mysql基础
    传智博客(JavaWeb方面的所有知识)听课记录(经典)
    nginx配置负载均衡与反向代理
    nginx 详解
    iOS开发之集成ijkplayer视频直播
    Nginx配置文件nginx.conf中文详解(总结)
    WorldWind源码剖析系列:数学引擎类MathEngine
    WorldWind源码剖析系列:二维点类Point2d和三维点类Point3d
    WorldWind源码剖析系列:枚举类型
  • 原文地址:https://www.cnblogs.com/DreamKill/p/9427771.html
Copyright © 2020-2023  润新知