CF830A.Office Keys
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
直线上有 n 个人和 k 把钥匙。每个人均需前往同样位于该直线上的办公室。为此,他必须先到达某处钥匙所在位置、拾取该钥匙,然后前往办公室。一旦某把钥匙被某人拾取,其他人便不能再拾取该钥匙。
你需要确定所有 n 个人均携钥匙抵达办公室所需的最短时间。假设每个人的移动速度为每秒 1 单位距离。若两人同时到达同一把钥匙所在位置,则仅其中一人可拾取该钥匙。一个人可以经过某把钥匙所在位置而不拾取它。
输入格式
The first line contains three integers n, k and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.
The second line contains n distinct integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109) — positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers _b_1, _b_2, ..., b__k (1 ≤ b__j ≤ 109) — positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
第一行包含三个整数 n、k 和 p(1≤n≤1000,n≤k≤2000,1≤p≤109)—— 分别表示人数、钥匙数以及办公室位置。
第二行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤109)—— 表示每个人初始所在的位置。这些位置以任意顺序给出。
第三行包含 k 个互不相同的整数 b1,b2,…,bk(1≤bj≤109)—— 表示各把钥匙的位置。这些位置以任意顺序给出。
注意:同一位置上不可能有超过一个人,也不可能有超过一把钥匙;但一个人和一把钥匙可以位于同一位置。
输出格式
Print the minimum time (in seconds) needed for all n to reach the office with keys.
输出所有人(共 n 人)拿到钥匙并到达办公室所需的最少时间(单位:秒)。
输入输出样例
输入#1
2 4 50 20 100 60 10 40 80
输出#1
50
输入#2
1 2 10 11 15 7
输出#2
7
说明/提示
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys.
在第一个例子中,位于点 20 的人应取走位于点 40 的钥匙,并携带它前往位于点 50 的办公室,耗时 30 秒。位于点 100 的人可取走位于点 80 的钥匙,并携带它前往办公室,耗时 50 秒。因此,50 秒后,所有人皆已携钥匙抵达办公室。
输入解题思路,AI测评打分。不知道怎么写?