Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int m, left, right, maxRight = 0, pos = 0;
- cin >> m;
- vector <pair <int, int> > segs, answer;
- while (cin >> left >> right) {
- segs.push_back(make_pair(left, right));
- }
- sort(segs.begin(), segs.end());
- while (maxRight < m) {
- int currLeft, currRight = maxRight;
- while (pos != segs.size() && segs[pos].first <= maxRight) {
- if (currRight < segs[pos].second) {
- currLeft = segs[pos].first;
- currRight = segs[pos].second;
- }
- ++pos;
- }
- if (currRight == maxRight) {
- cout << "No solution\n";
- return 0;
- }
- answer.push_back(make_pair(currLeft, currRight));
- maxRight = currRight;
- }
- cout << answer.size() << '\n';
- for (auto const &i : answer) {
- cout << i.first << ' ' << i.second << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement