zoukankan      html  css  js  c++  java
  • Codeforces 938.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
    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[100010];
    
    int main()
    {
        scanf("%d",&n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d",&a[i]);
            a[i] = min(a[i] - 1,1000000 - a[i]);
        }
        sort(a + 1,a + 1 + n);
        printf("%d
    ",a[n]);
    
        return 0;
    }
  • 相关阅读:
    HUD 1284 钱币兑换问题
    HUD 1284 钱币兑换问题
    HDU 1283 最简单的计算机
    HDU 1283 最简单的计算机
    商品搜索引擎---推荐系统设计
    Spark机器学习:TF-IDF实例讲解
    【读书笔记】Elasticsearch集成Hadoop最佳实践
    Java面试题集合
    Spring Boot企业微信点餐系统-第一章-课程介绍
    Eclipse下svn的创建分支/合并/切换使用
  • 原文地址:https://www.cnblogs.com/zbtrs/p/8451879.html
Copyright © 2011-2022 走看看