http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1091&judgeId=494877
我以为只是起点从小到大,终点从大到小排序就行了,然后两个两个的找重叠部分就行了,结果。。。这种情况不行:
5
2 8
2 4
3 7
这种是第一个和第三个重叠最大~~~
所以要维护一个 i-1 之前终点的最大值,与第i次的终点取最小,才是重叠区间的终点。。。
重叠部分的起点就是i的起点,因为是递增的~

#include"iostream"
#include"algorithm"
using namespace std;
const int maxn=5e4+5;
int N;
struct AAA
{
    int t1,t2;
    bool operator<(const AAA &a)const
    {
        if(t1==a.t1)return a.t2<t2;
        else return t1<a.t1;
    }
};
AAA a[maxn];
int main()
{
    while(cin>>N)
    {
        for(int i=1;i<=N;i++)cin>>a[i].t1>>a[i].t2;
        sort(a+1,a+1+N);
        int ans=0;
        int tt=0;
        for(int i=2;i<=N;i++)
        {
            tt=max(tt,a[i-1].t2);
            ans=max(ans,min(tt,a[i].t2)-a[i].t1);
        }

        cout<<ans<<"\n";
    }
}