当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6364:Ringland

题目描述
Patrick Star found the Ringland! It's marriage season in Ringland!

Ringland has a form of a circle's boundary of length $L$.

There are $N$ bridegrooms and $N$ brides, and bridegrooms decided to marry brides.

Of course, each bridegroom should choose exactly one bride, and each bride should be chosen by exactly one bridegroom.

All objects in Ringland are located on the boundary of the circle, including the capital, bridegrooms' castles and brides' palaces. The castle of the i-th bridegroom is located at the distance $a_i$ from the capital in clockwise direction, and the palace of the i-th bride is located at the distance $b_i$ from the capital in clockwise direction.

Let's define the inconvenience of a marriage the summary distance of every bride should walk along the circle from her palace to her bridegroom's castle in the shortest direction (in clockwise or counter-clockwise direction).

Help Patrick Star to calculate the smallest inconvenience among all marriages !
输入解释
The first line contain a integer $T$ (no morn than 10), the following is $T$ test case, for each test case :

The first line contains two integers $N$ and $L$ ($1 \le N \le 5 * 10^5, 1\le L \le 10^9$) --- the number of bridegrooms and brides and the length of Ringland.

The next line contains $N$ integers, $a_1, a_2, ..., a_n$ ($0 \le a_1 \le a_2 \le ... \le a_n < L$) --- the distances from the capital to the castles of bridegrooms in clockwise direction.

The next line contains $N$ integers, $b_1, b_2, ..., b_n$ ($0 \le b_1 \le b_2 \le ... \le b_n < L$) --- the distances from the capital to the palaces of brides in clockwise direction.

Attention: you may need fast read function.
输出解释
For each test case print one line,

This line contain only one integer, the smallest possible inconvenience of the wedding.
输入样例
1
2 5
3 4
0 2
输出样例
2
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6364

最后修改于 2020-10-25T23:30:40+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 131072/131072K(Java/Others)