gt22

Untitled

Oct 10th, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <vector>
  2. #include "optimization.h"
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int m = readInt();
  8.     vector<pair<int, int>> arr, ans;
  9.     while(true) {
  10.         int a = readInt(), b =readInt();
  11.         if(a == 0 && b == 0) {
  12.             break;
  13.         }
  14.         arr.emplace_back(a, b);
  15.     }
  16.     sort(arr.begin(), arr.end());
  17.     int curR = 0;
  18.     for (int i = 0; i < arr.size(); ++i) {
  19.         int lbound = arr[i].first;
  20.         if(lbound > curR) {
  21.             if(i == 0 || arr[i-1].second <=curR) {
  22.                 writeWord("No solution\n");
  23.                 return 0;
  24.             } else {
  25.                 curR = arr[i-1].second;
  26.                 ans.push_back(arr[i-1]);
  27.                 if(curR >= m) {
  28.                     break;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.     if(curR < m) {
  34.         if(arr[arr.size() - 1].second < m) {
  35.             //writeWord("No solution\n");
  36.             return 1;
  37.         }
  38.         ans.push_back(arr[arr.size() - 1]);
  39.     }
  40.  
  41.     writeInt(ans.size(), '\n');
  42.     for(auto p : ans) {
  43.         writeInt(p.first, ' ');
  44.         writeInt(p.second, '\n');
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment