SHARE
TWEET

Untitled

a guest May 25th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define all(x) begin(x), end(x)
  6.  
  7. using ll = long long;
  8. using ld = long double;
  9. using pii = pair<int, int>;
  10. using vi = vector<int>;
  11.  
  12. int main() {
  13.     ios_base::sync_with_stdio(false);
  14.     cin.tie(0); cout.tie(0);
  15.  
  16.     int n, m;
  17.     cin >> n >> m;
  18.     vector<tuple<int, int, int>> a;
  19.     for (int i = 0; i < n; ++i) {
  20.         int l, r;
  21.         cin >> l >> r;
  22.         a.emplace_back(l, r, i);
  23.     }
  24.     sort(all(a));
  25.  
  26.     int ptr = 0;
  27.     int cur = 1;
  28.     int max_r = 0;
  29.     vi ans;
  30.     while (cur <= m) {
  31.         int idx = -1;
  32.         while (ptr < n and get<0>(a[ptr]) <= cur) {
  33.             if (get<1>(a[ptr]) > max_r) {
  34.                 max_r = get<1>(a[ptr]);
  35.                 idx = get<2>(a[ptr]);
  36.             }
  37.             ++ptr;
  38.         }
  39.  
  40.         if (idx == -1) {
  41.             ans.clear();
  42.             break;
  43.         } else {
  44.             ans.push_back(idx);
  45.             cur = max_r + 1;
  46.         }
  47.     }
  48.  
  49.     if (ans.empty()) {
  50.         cout << "NO\n";
  51.     } else {
  52.         cout << "YES\n";
  53.         cout << ans.size() << '\n';
  54.         for (int x : ans) {
  55.             cout << (x + 1) << ' ';
  56.         }
  57.     }
  58.  
  59.     return 0;
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top