选择的钥匙一定是连续的,人和钥匙一定从左到右连续对应。

就枚举钥匙区间即可。

#include<cstdio>
#include<algorithm>
using namespace std;
int Abs(int x){
return x<0 ? (-x) : x;
}
int n,K,p,a[1010],ans=2147483647,b[2010];
int main(){
scanf("%d%d%d",&n,&K,&p);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
for(int i=1;i<=K;++i){
scanf("%d",&b[i]);
}
sort(a+1,a+n+1);
sort(b+1,b+K+1);
for(int i=1;i<=K;++i){
if(i+n-1>K){
break;
}
int maxx=0;
for(int j=1,k=i;j<=n;++j,++k){
maxx=max(maxx,Abs(a[j]-b[k])+Abs(b[k]-p));
}
ans=min(ans,maxx);
}
printf("%d\n",ans);
return 0;
}

【推导】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) A. Office Keys的更多相关文章

  1. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys time limit per test2 seconds 二分

    D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C

    A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. HDU 1465 不容易系列之一 (错排公式+容斥)

    题目链接 Problem Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好"一件"事情尚且不易,若想永远成功而总从不失败,那更是难上 ...

  2. js 合并多个对象 Object.assign

    Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象.它将返回目标对象. var o1 = { a: 1 };var o2 = { b: 2 };var o3 ...

  3. java基础 运算符

    算数运算符 加号:在操作数值.字符.字符串时其结果是不同的,当两个字符相加得到的是ASCII码表值, 当两个字符串相加时表示将两个字符串连接在一起,从而组成新的字符串. 除号:整数在使用除号操作时,得 ...

  4. Reactor与Proactor区别

    如网络编程中accept之后等待数据到达,并且读取数据为例: Reactor: 基于同步IO 1. 线程等待读取socket数据,将socketfd添加到事件分派器中,如添加到epoll: 2. 事件 ...

  5. python基础===将json转换为dict的办法

    首先json是字符串. 大家都知道,字符串是用来传递信息的.json字符串实际上就是一种规定了格式的字符串, 通过这种格式,我们可以在不同的编程语言之间互相传递信息,比如我们可以把javascript ...

  6. GitHub创建项目入门学习

    第一次创建git项目注意事项还是挺多了,这里就写个操作步骤,方便以后查看. 网页部分 1.打开自己的主页,点击“New repository”创建远程仓库. 2.填写信息 本地部分 前提: 下载git ...

  7. linux命令(35):head命令

    1.命令格式: head [参数]... [文件]... 2.命令功能: head 用来显示档案的开头至标准输出中,默认head命令打印其相应文件的开头10行. 3.命令参数: -q 隐藏文件名 -v ...

  8. POJ-2778

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12726   Accepted: 4862 Des ...

  9. Storm实战常见的问题

    该文档为实实在在的原创文档,转载请注明: http://blog.sina.com.cn/s/blog_8c243ea30101k0k1.html 类型 详细 备注 该文档是群里几个朋友在storm实 ...

  10. Merge Intervals——STL的应用

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...