Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define eps 1e-1
- typedef long long ll;
- typedef unsigned long long ull;
- using namespace std;
- const ll fix=(ll)1e10;
- multiset<pair<ll, ll>> mset;
- int main(){
- ifstream fin("cover.in");
- ofstream fout("cover.out");
- ll n, m;
- fin >> n;
- ll a, b;
- fin >> a >> b;
- while (a!=0 || b!=0) {
- ll tmp=a;
- a=min(a, b);
- b=max(tmp, b);
- mset.insert({a, b});
- fin >> a >> b;
- }
- set<pair<ll, ll>> res1;
- pair<ll, ll> prevPair = *mset.begin();
- ll beg=0;
- ll end=0;
- beg = prevPair.first;
- end = prevPair.second;
- for (auto&s:mset){
- if (end<s.first){
- res1.insert({beg,end});
- prevPair=s;
- end=s.second;
- beg=s.first;
- }
- beg=min(beg,s.first);
- end=max(end,s.second);
- if (s==*mset.rbegin())
- res1.insert({beg, end});
- }
- bool boo=false;
- for (auto&re:res1)
- if (re.first<=0 && re.second>=n)
- boo=true;
- if (!boo){
- fout << "No solution";
- return 0;
- }
- set<pair<ll, ll>> res;
- ll prevbord=(ll)-1e9;
- ll bord=0;
- while(true){
- ll maxCov=0;
- pair<ll,ll> maxPair={0,0};
- for (set<pair<ll, ll>>::iterator it = mset.lower_bound({prevbord, prevbord}); it!=mset.upper_bound({bord+1,bord+1}); ++it){
- if (((*it).second>maxCov)){
- maxCov=(*it).second;
- maxPair = (*it);
- }
- }
- res.insert(maxPair);
- prevbord=bord;
- bord=maxPair.second;
- if (bord>=n)
- break;
- }
- fout << res.size() << '\n';
- for (auto&re:res)
- fout << re.first << " " << re.second << '\n';
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement