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. 【1天】黑马程序员27天视频学习笔记【Day02】

    02.01常量的概述和使用 * A:什么是常量    * 在程序执行的过程中其值不可以发生改变 * B:Java中常量的分类    * 字面值常量    * 自定义常量(面向对象部分讲) * C:字面 ...

  2. SpringMVC中注解@RequestBody和@ResponseBody的使用区别

    首先上源码 在面试时经常会问到我们如何使用SpringMVC将Http请求转换为java对象,或者又是问如何将结果转换为java的呢? SpringMVC在接收到请求之后HandlerMapping像 ...

  3. CentOS 6安装配置mongodb

    安装过程 服务器下载安装包 下载: curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.0.6.tgz; 解压 ...

  4. LAB6 SOAP

    有web服务的,需要Deploy一下才能跑 通过ls看所有文件的所在地,cd进入对应文件夹,才可以编译 javac 编译,Java是执行 URL必须是WSDL文件点进去里面的:http://local ...

  5. java_26 缓冲流

    1.缓冲流: 读取数据大量的文件时,读取的速度慢, java提供了一套缓冲流,提高IO流的效率.分为字节缓冲流和字符缓冲流. 字节缓冲流: 缓冲输出流:BufferedOutputStream 缓冲输 ...

  6. ES查询-term VS match (转)

    原文地址:https://blog.csdn.net/sxf_123456/article/details/78845437 elasticsearch 中term与match区别 term是精确查询 ...

  7. Memcached和Memcache安装(64位win7)[z]

    http://www.cnblogs.com/lucky-man/p/6126667.html 一.Memcached和Memcache的区别: 网上关于Memcached和Memcache的区别的理 ...

  8. handsontable 常用 配置项 笔记

    import React, { Component } from 'react'; import HotTable from 'react-handsontable'; import Handsont ...

  9. java 实现udp通讯

    需求:应用A(通常有多个)和应用B(1个)进行 socket通讯,应用A必须知道应用B的ip地址(在应用A的配置文件中写死的),这个时候就必须把应用B的ip设成固定ip(但是某些时候如更换路由后要重新 ...

  10. Scania SDP3 2.38.2.37.0 Download, Install, Activate: Confirmed

    Download: Scania Diagnos & Programmer SDP3 2.38.2.37.0 free version and tested version SDP3 2.38 ...