Skip to content

Instantly share code, notes, and snippets.

@hhjeong
Created September 8, 2015 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhjeong/3d6102d70a11df52c9da to your computer and use it in GitHub Desktop.
Save hhjeong/3d6102d70a11df52c9da to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
int main() {
typedef pair<int,int> ii;
int N;
cin >> N;
vector<ii> S(N);
for( auto &s : S ) {
cin >> s.second >> s.first;
if( s.first < s.second ) swap(s.first,s.second);
}
sort(S.begin(),S.end());
for( int i = 0 ; i < N ; ++i ) swap(S[i].first,S[i].second);
vector<int> sol;
vector<bool> used(N,false);
for( int i = 0 ; i < N ; ++i ) {
if( used[i] ) continue;
sol.push_back(S[i].second);
for( int j = i ; j < N ; ++j ) {
if( S[j].first <= S[i].second ) used[j] = true;
}
}
cout << sol.size() << endl;
for( auto s : sol ) {
cout << s << " ";
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment