ScanLine
unknown
c_cpp
4 years ago
767 B
13
Indexable
#include <bits/stdc++.h>
using namespace std;
vector <pair <int,int>> v;
int n;
bool cmp(pair <int,int> a, pair<int,int> b){
if (a.first<b.first) return true;
else if(a.first==b.first && a.second<b.second) return true;
else return false;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
int x1,x2;
cin>>x1>>x2;
v.push_back({x1,0});
v.push_back({x2,1});
}
sort(v.begin(),v.end(),cmp);
/* out sorted vector
for(int i=0;i<v.size();i++){
cout<<i+1<<' '<<v[i].first<<'\t'<<v[i].second<<endl;
}*/
int cnt = 0,mx = 0, nmx = v[0].first;
for(int i=0;i<v.size();i++){
if(v[i].second == 0) cnt++;
else cnt--;
if(mx < cnt) {mx=cnt; nmx=v[i].first;}
}
cout<<mx<<' '<<nmx;
}
Editor is loading...