CF1029C Maximal Intersection
题目描述
给定n个闭区间,现在要求从这些闭区间中删除一个区间,使得剩下的 $(n-1)$ 个区间的交集的长度最大,求这个最大值。
(p.s.:若这个区间为空集或它的左端点与右端点重合,则长度为 0;否则其长度为右端点在数轴上表示的数减去左端点在数轴上表示的数)
输入格式
第一行输入一个正整数 $n(2\le n\le 3\times10^5)$。
后面的 $n$ 行中每行输入两个自然数 $l,r$,表示一个闭区间 $[l,r](0\le l\le r\le 10^9)$。
输出格式
输出一个数,表示这个最大值。
Translated by @lhy930
说明/提示
In the first example you should remove the segment $ [3;3] $ , the intersection will become $ [2;3] $ (length $ 1 $ ). Removing any other segment will result in the intersection $ [3;3] $ (length $ 0 $ ).
In the second example you should remove the segment $ [1;3] $ or segment $ [2;6] $ , the intersection will become $ [2;4] $ (length $ 2 $ ) or $ [1;3] $ (length $ 2 $ ), respectively. Removing any other segment will result in the intersection $ [2;3] $ (length $ 1 $ ).
In the third example the intersection will become an empty set no matter the segment you remove.
In the fourth example you will get the intersection $ [3;10] $ (length $ 7 $ ) if you remove the segment $ [1;5] $ or the intersection $ [1;5] $ (length $ 4 $ ) if you remove the segment $ [3;10] $ .