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 ...
随机推荐
- VMware中Ubuntu开机时停在启动界面,不进入X-window的解决办法
启动Ubuntu虚拟机时,停在这个画面不动: 试了若干次,都是这样.尝试了新建一个虚拟机然后把.vmdk文件拷过去启动,无法解决. 尝试重启,在这个界面按esc进入grub: 选择恢复模式 recov ...
- python实现简单关联规则Apriori算法
from itertools import combinations from copy import deepcopy # 导入数据,并剔除支持度计数小于min_support的1项集 def lo ...
- C++基础 new和delete
1.new delete 的使用 (1)基本数据类型 ); delete p; int *p = (int *)malloc(sizeof(int)); *p = ;free(p); (2)数组 ]; ...
- POJ:3276-Face The Right Way(线性反转)
Face The Right Way Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6259 Accepted: 2898 De ...
- JVM——九大工具助你玩转Java性能优化
本文转载自 http://www.importnew.com/12324.html 本文由 ImportNew - 陈 晓舜 翻译自 idrsolutions.欢迎加入翻译小组.转载请参见文章末尾的要 ...
- python协程和IO多路复用
协程介绍 ...
- Idea中maven依赖图查看
技术交流群: 233513714 使用Intellij idea,想看看它的maven依赖图,根据eclipse的经验,不是很容易能找到Intellij idea对应的功能.在打开的pom.xml文件 ...
- tp事务处理
数据库事务处理见手册 逻辑事务处理 Model->startTrans(); // 开启事务 if(操作失败) { Model->rollback(); // 回滚 }else { Mod ...
- imageX.exe
imageX 编辑ImageX 是一个命令行工具,原始设备制造商 (OEM) 和公司可以使用它来捕获.修改和应用基于文件的磁盘映像以进行快速部署.ImageX 可以使用 Windows 映像 (.wi ...
- nodejs 操作mongodb, 增删改查
很久没有学node了,之前书看了一半,今天继续学发现版本问题很坑爹,按书例子执行一堆错误.想学nodejs操作db,百度半天,一堆sb写神马鸟玩儿?简简单单写一大堆还运行不了的.需要代码也是看别人写的 ...