CF981F.Round Marriage
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai from the capital in clockwise direction, and the palace of the i-th bride is located at the distance bi from the capital in clockwise direction.
Let's define the inconvenience of a marriage the maximum distance that some 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 the bridegrooms of Ringland to choose brides in such a way that the inconvenience of the marriage is the smallest possible.
Ringland 正值婚庆时节!
Ringland 的形状是一个周长为 L 的圆的边界。这里有 n 位新郎和 n 位新娘,新郎们决定迎娶新娘。
显然,每位新郎必须恰好选择一位新娘,且每位新娘也必须恰好被一位新郎选中。
Ringland 中所有物体(包括首都、新郎们的城堡以及新娘们的宫殿)均位于该圆的边界上。第 i 位新郎的城堡位于从首都沿顺时针方向距离 ai 处;第 i 位新娘的宫殿位于从首都沿顺时针方向距离 bi 处。
我们定义这场婚姻的“不便度”为:所有新娘中,从各自宫殿出发沿圆周以最短路径(顺时针或逆时针方向)抵达其新郎城堡所需行走的最大距离。
请帮助 Ringland 的新郎们为新娘们做出最优配对,使得婚姻的不便度尽可能小。
输入格式
The first line contains two integers n and L (1≤n≤2⋅105, 1≤L≤109) — the number of bridegrooms and brides and the length of Ringland.
The next line contains n integers a1,a2,…,an (0≤ai<L) — the distances from the capital to the castles of bridegrooms in clockwise direction.
The next line contains n integers b1,b2,…,bn (0≤bi<L) — the distances from the capital to the palaces of brides in clockwise direction.
第一行包含两个整数 n 和 L(1≤n≤2⋅105,1≤L≤109)—— 分别表示新郎和新娘的人数,以及环形国度 Ringland 的长度。
第二行包含 n 个整数 a1,a2,…,an(0≤ai<L)—— 表示各位新郎的城堡距首都的顺时针距离。
第三行包含 n 个整数 b1,b2,…,bn(0≤bi<L)—— 表示各位新娘的宫殿距首都的顺时针距离。
输出格式
In the only line print the smallest possible inconvenience of the wedding, where the inconvenience is the largest distance traveled by a bride.
在唯一的一行中输出婚礼的最小可能不便值,其中不便值定义为新娘所行走的最大距离。
输入输出样例
输入#1
2 4 0 1 2 3
输出#1
1
输入#2
10 100 3 14 15 92 65 35 89 79 32 38 2 71 82 81 82 84 5 90 45 23
输出#2
27
说明/提示
In the first example the first bridegroom should marry the second bride, the second bridegroom should marry the first bride. This way, the second bride should walk the distance of 1, and the first bride should also walk the same distance. Thus, the inconvenience is equal to 1.
In the second example let pi be the bride the i-th bridegroom will marry. One of optimal p is the following: (6,8,1,4,5,10,3,2,7,9).
在第一个例子中,第一位新郎应与第二位新娘结婚,第二位新郎应与第一位新娘结婚。这样,第二位新娘需行走距离 1,第一位新娘也需行走相同距离。因此,不便度等于 1。
在第二个例子中,设 pi 表示第 i 位新郎将迎娶的新娘编号。一个最优的 p 序列为:(6,8,1,4,5,10,3,2,7,9)。
输入解题思路,AI测评打分。不知道怎么写?