2753homework

2753   homework

题目描述

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.

输入格式:

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.

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

输出格式:

for each data set, output answer in one line.

输入样例 复制
2
1 2 10
11
15 7
2 4 50
20 100
60 10 40 80
输出样例 复制
7
50

说明

2
4
通过提交
时空限制2000ms/128mb
题目来源
评测方式在线评测
题目类型
难        度