文理学院程序设计在线练习


Homework

Time Limit: 2 Second(s)    Memory Limit: 32 MB

Total Submission(s): 23   Accepted Submission(s): 12
Problem Description

What a surprise that All students in EyeBigBird school lost their homework!
No one dares to go to school without homework. But fortunately, some places have homework that already done . Now each student needs to reach those place , get homework and then go to school.
We assume that all N students and K homework and school lie on a straight line , and students move a unit distance per 1 second . You are to determine the minimum time needed for all sutdents to get to the school with homework.
notice that once a homework is taken by somebody, it couldn't be taken by anybody else, and students can pass through a point with a homework without taking it.

Input

The first line contains a T which means the number of data sets
In each data set:
The first line contains three integers n, k and p — the number of students, the number of homework and the office school.
The second line contains n distinct integers a1, a2, ..., an — positions in which students are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk — positions of the homework. The positions are given in arbitrary order.

Limit:
T <= 10
n <= 1000
n <= k <= 2000
1 <= p, ai , bi <= 1e9

Output

for each data set, output answer in one line

Sample Input
2
1 2 10
11
15 7
2 4 50
20 100
60 10 40 80
Sample Output
7
50
Source

2018绍兴市联赛