CF14B.Young Photographer
入门
通过率:0%
时间限制:2.00s
内存限制:64MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position _x_0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position _a_1 to position _b_1, the second — from _a_2 to _b_2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
除了其他爱好之外,鲍勃热衷于摄影,尤其喜欢拍摄运动员。正因如此,他站在一条笔直长跑道的 x0 位置,准备拍照。但问题在于,并非所有运动员都会经过他所在的位置。在该跑道上训练的运动员总数为 n,且每位运动员均在跑道上的某个固定线段内规律性地奔跑(每位运动员的线段可能不同)。例如,第一位运动员在位置 a1 到 b1 之间奔跑,第二位运动员在 a2 到 b2 之间奔跑。
鲍勃至少需要移动多远的距离,才能确保有机会为每一位运动员拍照?当鲍勃所站位置位于某位运动员的奔跑线段内时,他即可为该运动员拍照。
输入格式
The first line of the input file contains integers n and _x_0 (1 ≤ n ≤ 100; 0 ≤ _x_0 ≤ 1000). The following n lines contain pairs of integers a__i, b__i (0 ≤ a__i, b__i ≤ 1000; a__i ≠ b__i).
输入文件的第一行包含整数 n 和 x0(1 ≤ n ≤ 100;0 ≤ x0 ≤ 1000)。接下来的 n 行每行包含一对整数 ai,bi(0 ≤ ai,bi ≤ 1000;ai = bi)。
输出格式
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
以赛道上位置所用的相同单位输出所需的最小距离。如果不存在这样的位置,则输出 -1。
输入输出样例
输入#1
3 3 0 7 14 2 4 6
输出#1
1
输入解题思路,AI测评打分。不知道怎么写?