Codeforces 938.B Run For Your Prize
1 second
256 megabytes
standard input
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?
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.
Print one integer — the minimum number of seconds it will take to collect all prizes.
3
2 3 9
8
2
2 999995
5
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的更多相关文章
- Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)
题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...
- 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 ...
- Codeforces 938.C Constructing Tests
C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 938.A Word Correction
A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 ...
- CF938B Run For Your Prize 题解
Content 有两个人,一个在 \(1\) 处,一个在 \(10^6\) 处,在他们之间有 \(n\) 个奖品,第 \(i\) 个奖品在 \(a_i\) 处.一开始在 \(1\) 处的人每秒可向右移 ...
- 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 ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
- 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 ...
随机推荐
- mysql 1055 的错误
1.Err1055,出现这个问题往往是在执行sql语句时候,在最后一行会出现这个问题. [Err] 1055 - Expression #1 of ORDER BY clause is not in ...
- 内置函数系列之 map
map(映射函数)语法: map(函数,可迭代对象) 可以对可迭代对象中的每一个元素,分别执行函数里的操作 # 1.计算每个元素的平方 lst = [1,2,3,4,5] lst_new = map( ...
- python——PIL(图像处理库)
PIL(Python Imaging Library,python图像处理库)提供了通用的图像处理功能,以及大量有用的基本图像操作,如图像缩放,裁剪,旋转,颜色转换等. 1.打开图像并显示 from ...
- Android 时间计算工具 通用类TimeUtil
1.整体分析 1.1.源代码如下,可以直接Copy. public class TimeUtil { private static final String TAG = "TimeUtil& ...
- J.U.C 系列 Tools之Executors
上个章节说了Tools中的其他四个工具类,本节我们来看一看工具类中的老大Executors,为什么说它是老大,肯定是因为他的功能最多最强大. 一 Executors是什么 Executors 是一个线 ...
- hover 改变另一个标签的属性
- Java Spring Controller 获取请求参数的几种方法
技术交流群:233513714 1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交.若"Content-Type"=& ...
- JavaScript获取时间
var myDate = new Date(); console.log(myDate.getFullYear()); //获取完整的年份(4位,1970-????) ...
- UR官网特效
<!DOCTYPE html> <!--申明文档类型:html--> <html lang="en&q ...
- java和c/c++
写c/c++的人,羡慕java可以自己管理内存 写java的人,羡慕c/c++没有gc问题