思路:暴力求区区最长覆盖
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define x first
#define y second
const int N = 110;
typedef pair<int, int> PII;
PII p[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>p[i].x>>p[i].y;
sort(p,p+n);
int res=0;
for(int i=0;i<n;i++){
int sum=0,st=-1,ed=-1;
for(int j=0;j<n;j++){
if(j!=i){
if(p[j].x<=ed) ed=max(ed,p[j].y);
else{
sum+=ed-st;
st=p[j].x,ed=p[j].y;
}
}
}
sum+=ed-st;
res=max(res,sum);
}
cout<<res<<endl;
return 0;
}