提交时间:2024-08-19 20:21:56
运行 ID: 50333
//区间合并 #include<bits/stdc++.h> using namespace std; struct node{ int x; int y; }a[50005]; bool cmp(node A,node B){ if(A.x==B.x) return A.y<B.y; else return A.x<B.x; } int main() { int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i].x>>a[i].y; } sort(a,a+n,cmp); int l=a[0].x; int r=a[0].y; for(int i=1;i<n;i++){ if(a[i].x>r){ cout<<"no\n"; return 0; } l=min(l,a[i].x); r=max(r,a[i].y); } cout<<l<<" "<<r<<" "<<endl; }