码迷,mamicode.com
首页 > 其他好文 > 详细

【推导】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) A. Office Keys

时间:2017-07-14 13:33:31      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:names   int   ret   algo   logs   nal   区间   class   max   

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

就枚举钥匙区间即可。

#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

标签:names   int   ret   algo   logs   nal   区间   class   max   

原文地址:http://www.cnblogs.com/autsky-jadek/p/7169420.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!