A

题意:给你人的坐标,钥匙的坐标,办公室的坐标。要求所有人能够拿到钥匙并且走到办公室的最短时间。一个位置只能有一个人,一个位置只有一把钥匙,人和钥匙可以在同一个位置。

思路:DP+贪心,dp[i]表示i这把钥匙被使用时人走的距离

代码:

#include<stdio.h>
#include<algorithm>
#include<string.h>
#define Inf 1e19;
#define ll long long
using namespace std;
int n,k;
ll p;
ll a[1100];
ll b[2200];
ll dp[2200];
int main()
{
while(~scanf("%d%d%I64d",&n,&k,&p))
{
for(int i=0; i<n; i++)
scanf("%I64d",&a[i]);
for(int i=0; i<k; i++)
scanf("%I64d",&b[i]);
sort(a,a+n);
sort(b,b+k);
ll ans=Inf;
memset(dp,0,sizeof(dp));
for(int i=0; i<k; i++)
{
if(i+n>k)
break;
for(int j=0; j<n; j++)
{
ll cnt=abs(b[i+j]-a[j])+abs(p-b[i+j]);
dp[i]=max(dp[i],cnt);
}
ans=min(ans,dp[i]);
}
printf("%I64d\n",ans);
}
return 0;
}

Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals)的更多相关文章

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

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

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

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

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

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

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

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

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

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - D

    题目链接:http://codeforces.com/contest/831/problem/D 题意:在一个一维坐标里,有n个人,k把钥匙(钥匙出现的位置不会重复并且对应位置只有一把钥匙),和一个终 ...

  10. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - C

    题目链接:http://codeforces.com/contest/831/problem/C 题意:给定k个评委,n个中间结果. 假设参赛者初始分数为x,按顺序累加这k个评委的给分后得到k个结果, ...

随机推荐

  1. TT-付款方式

    付款方式 一般T/T是可以的,上述客户我们采用的付款方式就是定金加TT,如果是信用证方式,那么需要资信良好的开证行: 中国工商银行 汇丰银行 渣打银行 花旗银行 MUSLIM COMMERCIAL B ...

  2. Python开发【第十一篇】:Python操作MySQL

    本篇对于Python操作MySQL主要使用两种方式: 1.原生模块pymsql. 2.ORM框架SQLAchemy. pymsql pymsql是Python中操作MySQL的模块,其使用方法和MyS ...

  3. mysql5.7.21安装要点记录

    下载的是Zip解压缩版,Windows系统,因为很久没有在Windows上安装过,这次安装发现了几处和以前安装不一样的地方,特记录如下,供大家参考 MySQL配置文件位置 bin目录下的mysql_c ...

  4. c/c++一维数组简单介绍

    定义:同一种类型数据的集合 通俗的讲就是,将多个同一种类型的数据按一定的内存顺序写在一起. 注意我的几个关键字“多个”,“同一种”,“一定的内存顺序”.如果理解了这几个关键词,说明你的数组已经掌握了. ...

  5. ARM汇编指令格式

    一.ARM介绍 1) arm汇编中,程序下一步执行哪一条指令,是根据程序计数器(PC)的值来决定. 类比于8086的CS:IP的功能. 2) 8086属于CISC(复杂指令集),每条指令长度不等,ar ...

  6. vscode和gitee的使用

    1.安装git 2.生成公钥 $ ssh-keygen -t rsa -C "youremail@youremail.com" # Generating public/privat ...

  7. Windows10开机pin界面循环重启解决办法

    昨天电脑在开机时,进入pin界面,输入pin码之后系统没反应,也不显示登陆成功,大概一分钟之后自动重启,遂百度答案:大部分建议都是在开机显示win图标时强制关机,强制关机两次即自动进入疑难解答页面,以 ...

  8. ng环境搭建步骤

    1,安装node node -v查看版本号 2,安装淘宝镜像 npm config set registry https://registry.npm.taobao.org 3,安装cnpm npm ...

  9. 生信分析常用脚本(二)--SOAPdenovo

    1.SOAPDenovo配置文件示例 软件下载安装和使用:http://soap.genomics.org.cn/soapdenovo.html asm.cfg #maximal read lengt ...

  10. 图解Golang的GC算法

    虽然Golang的GC自打一开始,就被人所诟病,但是经过这么多年的发展,Golang的GC已经改善了非常多,变得非常优秀了. 以下是Golang GC算法的里程碑: v1.1 STW v1.3 Mar ...