【推导】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) A. Office Keys
选择的钥匙一定是连续的,人和钥匙一定从左到右连续对应。
就枚举钥匙区间即可。
#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的更多相关文章
- 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 ...
- 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 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 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 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 ...
随机推荐
- 大聊Python----通过Socket实现简单的ssh客户端
光只是简单的发消息.收消息没意思,干点正事,可以做一个极简版的ssh,就是客户端连接上服务器后,让服务器执行命令,并返回结果给客户端. #ssh_client.py import socket cli ...
- bzoj 3197 DP
这道题我们可以看成给定两个黑白树,可以修改其中一棵树的颜色,问最少修改多少颜色可以使两棵树同构. 首先我们知道在树的同构中树上最长链中点(如果是偶数的话就是中间两个点)是不变的,我们把这个点叫做树的重 ...
- window对象的方法和属性汇总
window对象有以下方法: open close alert confirm prompt setTimeout clearTimeout setInterval clearInterval mov ...
- hdu 1016 Prime Ring Problem (素数环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 题目大意:输入一个n,环从一开始到n,相邻两个数相加为素数. #include <iost ...
- 【EverydaySport】健身笔记——背部训练
背部训练大致可以分为两种. 1 下拉式动作 躯干纵向上下位移的动作 典型代表 这样的下拉类动作 针对的是背阔肌 也就是两边像翅膀一样的部分 2 垂直于躯干的方向作用 向内拉 主要针对的是,背部的中部 ...
- shellcheck 帮助你写出更好的脚本
简介 shellcheck 是一款实用的 shell脚本静态检查工具. 首先,可以帮助你提前发现并修复简单的语法错误,节约时间.每次都需要运行才发现写错了一个小地方,确实非常浪费时间. 其次,可以针对 ...
- SourceTree 过期,注册导入许可证
参考这里:SourceTree过期,需要注册导入 SourceTree License 许可证 很详细 补充: 如果在 SourceTree 软件里注册失败,可以在网页注册. 如果其他邮箱不支持,可以 ...
- python基础===输入必须为数字的检验的另一种方法
print("[+]welcome to python3") while True: num = input("please input a num:") if ...
- .net爬虫了解一下
using System; //添加selenium的引用 using OpenQA.Selenium.PhantomJS; using OpenQA.Selenium.Chrome; using O ...
- MYSQL5.5源码安装 linux下
/* 首先安装必要的库 */ yum -y install gcc* ###### 安装 MYSQL ###### 首先安装camke 一.支持YUM,则 yum install -y cmake 二 ...