#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int a[];
int b[];
int dp[][];
//dp[i][j] 前i个人从前j个药匙中到达终点的最小时间 int main()
{
int n,k,p;
while(~scanf("%d%d%d",&n,&k,&p))
{
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=k;i++) scanf("%d",&b[i]);
sort(a+,a++n);
sort(b+,b++k); for(int i=;i<=n;i++)
{
for(int j=i;j<=k;j++)
{
if(i==j)
{
dp[i][j]=max(dp[i-][j-],abs(p-b[j])+abs(a[i]-b[j]));
continue;
}
dp[i][j]=min(dp[i][j-],max(dp[i-][j-],abs(p-b[j])+abs(a[i]-b[j])));
}
} int ans = INT_MAX;
for(int i = n;i <= k;i++)
{
ans = min(ans,dp[n][i]);
}
printf("%d\n",ans);
}
return ;
}

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

  1. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Office Keys(思维)

    Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

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

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

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

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

    选择的钥匙一定是连续的,人和钥匙一定从左到右连续对应. 就枚举钥匙区间即可. #include<cstdio> #include<algorithm> using namesp ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Cards Sorting(树状数组)

    Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input ...

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

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

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

随机推荐

  1. Composite Pattern

    1.将对象组合成树形结构以表示“部分--整体”的层次结构.组合模式使得用户对单个对象和组合对象的使用具有一致性. 2.Composite 模式结构图 3.实现 #ifndef _COMPONENT_H ...

  2. 解决Android Studio Fetching Android SDK component information失败问题【转】

    本文转载自:http://blog.csdn.net/isesar/article/details/41908089 Android Studio 安装完成后,如果直接启动,Android Studi ...

  3. hdu 1205 吃糖果(抽屉原理)

    题意:N种糖果,不能把一样的放在一起吃,即第一次吃一种,下一次吃另一种. 思路:找到个数最多的糖果种类(最大的数目记作 ma,该糖果种类记为a),首先把这n个糖果放到n个抽屉里面,然后把剩余的N-1种 ...

  4. C# 多线程控制 通讯 和切换

    一.多线程的概念  Windows是一个多任务的系统,如果你使用的是windows 2000及其以上版本,你可以通过任务管理器查看当前系统运行的程序和进程.什么是进程呢?当一个程序开始运行时,它就是一 ...

  5. kallsyms

    kallsyms 在v2.6.0的内核中,为了更好地调试内核,引入新的功能kallsyms.kallsyms把内核用到的所有函数地址和名称连接进内核文件,当内核启动后,同时加载到内存中.

  6. BZOJ_2208_[Jsoi2010]连通数_强连通分量+拓扑排序+手写bitset

    BZOJ_2208_[Jsoi2010]连通数_强连通分量+拓扑排序+手写bitset Description Input 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i ...

  7. [ZJOI 2013] K大数查询

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3110 [算法] 整体二分 + 线段树 时间复杂度 : O(NlogN ^ 2) [代 ...

  8. codevs 1147 排座椅

    传送门 题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情.不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接 ...

  9. bzoj 4827 [Hnoi2017] 礼物 —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4827 首先,旋转对应,可以把 b 序列扩展成2倍,则 a 序列对应到的还是一段区间: 再把 ...

  10. vue render函数使用jsx语法 可以使用v-model语法 vuex实现数据持久化

    render函数使用jsx语法: 安装插件  transform-vue-jsx 可以使用v-model语法安装插件 jsx-v-model .babelrc文件配置: vuex实现数据持久化 安装插 ...