Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include "optimization.h"
- using namespace std;
- int main() {
- int m = readInt();
- vector<pair<int, int>> arr, ans;
- while(true) {
- int a = readInt(), b =readInt();
- if(a == 0 && b == 0) {
- break;
- }
- arr.emplace_back(a, b);
- }
- sort(arr.begin(), arr.end());
- int curR = 0;
- for (int i = 0; i < arr.size(); ++i) {
- int lbound = arr[i].first;
- if(lbound > curR) {
- if(i == 0 || arr[i-1].second <=curR) {
- writeWord("No solution\n");
- return 0;
- } else {
- curR = arr[i-1].second;
- ans.push_back(arr[i-1]);
- if(curR >= m) {
- break;
- }
- }
- }
- }
- if(curR < m) {
- if(arr[arr.size() - 1].second < m) {
- //writeWord("No solution\n");
- return 1;
- }
- ans.push_back(arr[arr.size() - 1]);
- }
- writeInt(ans.size(), '\n');
- for(auto p : ans) {
- writeInt(p.first, ' ');
- writeInt(p.second, '\n');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment