
1 #include <bits/stdc++.h> 2 #define _xx ios_base::sync_with_stdio(0);cin.tie(0); 3 using namespace std; 4 typedef long long ll; 5 struct node 6 { 7 int s, e; 8 } a[50005]; 9 bool operator < (const node& t1, const node& t2) 10 { 11 return t1.s < t2.s; 12 } 13 int main() 14 {_xx 15 int n, ans = 0; 16 cin >> n; 17 for(int i = 1; i <= n; i++) cin >> a[i].s >> a[i].e; 18 sort(a + 1, a + n + 1); 19 int lmost = 0; 20 for(int i = 1; i <= n; i++) 21 { 22 if(lmost <= a[i].e) ans = max(ans, lmost - a[i].s); 23 else ans = max(ans, a[i].e - a[i].s); 24 lmost = max(lmost, a[i].e); 25 } 26 cout << ans << endl; 27 return 0; 28 }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步