【链接】:
http://codeforces.com/contest/1029/problem/B
【题意】:
去掉一个区间,求所有区间覆盖的区间的最大值
【思路】:
答案区间肯定是一个左端点,一个右端点,维护两个multiset,暴力删除,插入(nlgn).
【代码】:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 6;
struct node {int l, r;
}k[maxn];multiset<int>L,R;int main() {int n;scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d%d", &k[i].l, &k[i].r);L.insert(k[i].l);R.insert(k[i].r);}int ans = 0;for (int i = 1; i <= n; i++) {auto id = L.find(k[i].l);L.erase(id);id = R.find(k[i].r);R.erase(id);ans = max(ans, *R.begin() - *L.rbegin());L.insert(k[i].l);R.insert(k[i].r);}printf("%d\n", ans);
}