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

    摘要:我们已经学过正则表达式了,所以现在开始学习 grep 也是水到渠成的事情. 简介:grep 是 Linux 中最常用的“文本处理工具”之一,grep 与 sed.awk 合称为 Linux 中的 ...

  2. Java第二周作业

    Java第二周作业 本周作业: 参考http://www.cnblogs.com/rocedu/p/7911138.html 学习第二三章视频 参考http://www.cnblogs.com/roc ...

  3. C# Common Code

    DatePicker 控件日期格式化,可以在App.xaml.cs中添加下面代码 方法一 不推荐: Thread.CurrentThread.CurrentCulture = (CultureInfo ...

  4. SwipeBackLayout 右滑退出Activity

    不推荐通过添加依赖的方式来导入类库,因为本人导入后出现没法解决的问题. 这里推荐自己导入第三方库类,地址如下: https://github.com/yangzhilong00/MEvolution/ ...

  5. AFNetworking Delete请求,报参数为空的错误

    使用AFNetWorking进行网络请求的时候,AFNetWorking会默认把get head delete这三个方法的请求参数拼到了url的后面,然后造成body为空,一行代码解决: manage ...

  6. JavaSE基础知识(5)—面向对象(方法的重写与重载)

    一.重写 1.说明 子类对继承过来的父类的方法进行改造,这种现象称为方法的重写或覆盖或覆写(Override) 2.要求 方法签名完全一致,jdk5.0之后,允许返回类型可以是子类类型,权限修饰符可以 ...

  7. 刷shipid 简便方法

    将表中的数据手动更改: select * from cmpps025 where  pino = ''; insert into cmpps025 select ncmp, pino, pono, i ...

  8. POS VB

    PPSM06S70:  Add  moddate EDITSPRINTJOB:  MAX(TO_CHAR(ETRN.MODDATE, 'yyyy/mm/dd/HH24:MI AM')) ACTUAL_ ...

  9. JavaSE 初学系统托盘图标SystemTray类

    文章目录 1.预备知识 2.使系统托盘显示图标 3.添加提示 4.添加弹出菜单 设置Java程序的系统托盘图标,用到SystemTray类和TrayIcon类. 1.预备知识 JavaAPI对于Sys ...

  10. html 页面 判断第一个反应的网站并进行跳转 模仿CDN

    <!DOCTYPE html><html><head><meta charset="gb2312"><meta http-eq ...