MiinaMagdy

12356 - Army Buddies

Sep 8th, 2022
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define endl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  12.     int s, b, l, r;
  13.     while (cin >> s >> b, s || b) {
  14.         set<int> st;
  15.         for (int i = 1; i <= s; i++) st.insert(i);
  16.         for (int i = 0; i < b; i++) {
  17.             cin >> l >> r;
  18.             for (int j = l; j <= r; j++) st.erase(j);
  19.             auto it1 = st.lower_bound(l);
  20.             auto it2 = st.lower_bound(r);
  21.             if (it1 != st.begin()) {
  22.                 it1--; 
  23.                 if (it1 != st.end()) {
  24.                     cout << *it1;
  25.                 }
  26.                 else cout << "*";
  27.             }
  28.             else cout << "*";
  29.            
  30.             cout << " ";
  31.             if (it2 != st.end()) cout << *it2;
  32.             else cout << "*";
  33.             cout << endl;
  34.         }
  35.         cout << "-\n";
  36.     }
  37. }
  38.  
Tags: UVA CP3
Advertisement
Add Comment
Please, Sign In to add comment