Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys time limit per test2 seconds 二分
2 seconds
256 megabytes
standard input
standard output
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
The first line contains three integers n, k and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 ≤ bj ≤ 109) — positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Print the minimum time (in seconds) needed for all n to reach the office with keys.
2 4 50
20 100
60 10 40 80
50
1 2 10
11
15 7
7
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50seconds. Thus, after 50 seconds everybody is in office with keys.
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=2e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; int n,k;
LL a[N],b[N],p;
LL dis(LL s,LL mid,LL e)
{
return abs(mid-s)+abs(e-mid);
}
int check(LL x)
{
int s=,flag=;
for(int i=;i<=n;i++)
{
while(s<=k&&dis(a[i],b[s],p)>x)s++;
if(s>k){
flag=;
break;
}
s++;
}
if(!flag)return ;
return ;
}
int main()
{
scanf("%d%d%lld",&n,&k,&p);
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=;i<=k;i++)
scanf("%lld",&b[i]);
sort(a+,a++n);
sort(b+,b++k);
LL s=,e=1e10,ans=-;
while(s<=e)
{
LL mid=(s+e)>>;
if(check(mid))
{
ans=mid;
e=mid-;
}
else s=mid+;
}
printf("%lld\n",ans);
return ;
}
Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys time limit per test2 seconds 二分的更多相关文章
- 【推导】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) A. Office Keys
选择的钥匙一定是连续的,人和钥匙一定从左到右连续对应. 就枚举钥匙区间即可. #include<cstdio> #include<algorithm> using namesp ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C
A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B
Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...
随机推荐
- HDU 1233 还是畅通工程 (最小生成树 )
某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路 ...
- bzoj2287 [POJ Challenge]消失之物
题目链接 少打个else 调半天QAQ 重点在47行,比较妙 #include<algorithm> #include<iostream> #include<cstdli ...
- Linux下解析域名命令-dig 命令使用详解
Linux下解析域名除了使用nslookup之外,开可以使用dig命令来解析域名,dig命令可以得到更多的域名信息.dig 命令主要用来从 DNS 域名服务器查询主机地址信息.dig的全称是 (dom ...
- 解决Win 10上SSD缓慢问题
标准硬盘驱动器(HDD)由于其高存储容量和低成本而长期以来一直是计算机的主要存储设备.固态硬盘(SSD)是另一种存储解决方案,正在逐步取代大多数硬盘驱动器.但是,随着时间的推移,SSD会因各种原因而大 ...
- SpringMVC实现 MultipartFile 文件上传
1. Maven 工程引入所需要的依赖包 2. 页面需要开放多媒体标签 3. 配置文件上传试图解析器 4. 接收图片信息,通过 IO 流写入磁盘(调用解析其中的方法即可) 如下: 1.1 引入所依赖的 ...
- 【移动端】js禁止页面滑动与允许滑动
禁止页面滑动 通常静止滑动方案:(阻止滑动事件) window.ontouchmove=function(e){ e.preventDefault && e.preventDefaul ...
- elasticsearch配置文件详解
来自:http://www.searchtech.pro/articles/2013/02/18/1361194291548.html elasticsearch的config文件夹里面有两个配置文 ...
- nginx: [error] invalid PID number "" in "/var/run/nginx/nginx.pid"
一.出现这个的情况 解决方法一: 1.添加正在运行pid号到/var/run/nginx/nginx.pid就可以解决问题了(这个情况是在重启的情况下发现的) 2.如果是重启机器之后,系统有时会删掉/ ...
- caffe中的若干问题
找不到cublas....: 在/etc/ld.so.conf文件夹中新建cuda.conf,里面添加/usr/local/cuda/lib64,然后sudo /sbin/ldconfig -v. c ...
- Spring <import>标签配置
使用情景:在Maven项目中,我们在Spring 配置文件中需要用到<import resource="">标签来引入其他配置文件,这里我要记下一些注意事项 情景1 & ...