CF2193F.Pizza Delivery
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Courier YF has earned the title of the best pizza delivery person GR. The manager does not like him, so he decided to give him a very difficult task. The manager provided him with n coordinates of houses (xi,yi) where he needs to deliver the pizza. He will deliver the pizza in the following way:
- GR pizza is prepared at the point (Ax,Ay) and YF starts the delivery from this point.
- To deliver the pizza, he can move from the point (x,y) to three points (x+1,y), (x,y+1), (x,y−1).
- After he has delivered all the pizzas, he returns home to the point (Bx,By).
Each move takes him exactly one second, and handing over the pizza to the customer takes 0 seconds. The manager wants the delivery to be as fast as possible. You need to find the minimum delivery time for all GR pizzas. It is guaranteed that delivery is always possible.
快递员 YF 获得了“最佳披萨配送员 GR”的称号。经理不喜欢他,因此决定给他一个非常困难的任务。经理向他提供了 n 个房屋的坐标 (xi,yi),他需要将披萨配送到这些地点。他将按以下方式完成披萨配送:
- GR 披萨在点 (Ax,Ay) 处制作完成,YF 从该点出发开始配送;
- 为完成配送,他可以从点 (x,y) 移动至以下三个点之一:(x+1,y)、(x,y+1)、(x,y−1);
- 在完成所有披萨的配送后,他需返回家中,即点 (Bx,By)。
每次移动恰好耗时一秒,而将披萨交付给顾客的过程不耗时(耗时为 0 秒)。经理希望整个配送过程尽可能快。你需要求出配送全部 GR 披萨所需的最短时间。题目保证配送总是可行的。
输入格式
Each test consists of several test cases. The first line contains one integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains five integers n, Ax, Ay, Bx, By (1≤n≤2⋅105, 1≤Ax,Ay,Bx,By≤109) — the number of houses for delivery, as well as the coordinates of the start and end points.
The second line of each test case contains n integers x1,x2,…,xn (Ax<xi<Bx).
The third line of each test case contains n integers y1,y2,…,yn (1≤yi≤109).
It is guaranteed that the sum of the values of n across all test cases does not exceed 2⋅105.
每个测试包含若干测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含五个整数 n、Ax、Ay、Bx、By(1≤n≤2⋅105,1≤Ax,Ay,Bx,By≤109),分别表示待配送房屋的数量,以及起点和终点的坐标。
每个测试用例的第二行包含 n 个整数 x1,x2,…,xn(满足 Ax<xi<Bx)。
每个测试用例的第三行包含 n 个整数 y1,y2,…,yn(满足 1≤yi≤109)。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output a single integer on a separate line — the minimum time required for pizza delivery.
对于每个测试用例,在单独一行输出一个整数——披萨配送所需的最短时间。
输入输出样例
输入#1
4 1 2 3 5 2 4 4 3 1 3 5 2 3 4 3 5 4 1 6 1 2 7 3 5 2 3 5 5 3 6 4 3 1 4 1 5 6 9 8 6 7 7 7 7 7 3 1 8 8 3
输出#1
6 13 19 15
说明/提示
Consider the second test case:
- Move from the point (Ax,Ay) to the point (x3,y3) in 4 seconds.
- Move from the point (x3,y3) to the point (x1,y1) in 4 seconds.
- Move from the point (x1,y1) to the point (x2,y2) in 2 seconds.
- Move from the point (x2,y2) to the point (Bx,By) in 3 seconds.
In total, the delivery takes 4+4+2+3=13 seconds. It can be proven that it is impossible to deliver the pizza faster.
考虑第二个测试用例:
- 从点 (Ax,Ay) 移动到点 (x3,y3),耗时 4 秒。
- 从点 (x3,y3) 移动到点 (x1,y1),耗时 4 秒。
- 从点 (x1,y1) 移动到点 (x2,y2),耗时 2 秒。
- 从点 (x2,y2) 移动到点 (Bx,By),耗时 3 秒。
总计,配送耗时 4+4+2+3=13 秒。可以证明,无法以更短的时间完成披萨配送。
输入解题思路,AI测评打分。不知道怎么写?