CF938B Run For Your Prize

传送门
题意大意

在一条线上,你在1处,朋友在10^6 处,你们两中间有n个礼物第i个礼物坐标为ai 你们两个的速度为1,,被经过的礼物就被认为是捡起的,你们想把所有礼物捡起,问最少要多少秒。

挺简单的 对于每一个礼物 取朋友到它和我到它的最小值 在这些最小值中取max

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 1000000
int N,ans=-1;
int a[MAXN+5];
int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&a[i]);
        ans=max(ans,min(a[i]-1,MAXN-a[i]));
    }
    printf("%d\n",ans);
}

猜你喜欢

转载自blog.csdn.net/cqbzlytina/article/details/79470140