SHARE
TWEET

Untitled

a guest Nov 5th, 2016 185 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. struct event {
  6.     int w, c, type, ind; //0 - zerg 1 - axe
  7.  
  8.     event(int w, int c, int type, int ind):w(w), c(c), type(type), ind(ind){}
  9.  
  10.     bool operator <(const event& arg) const {
  11.         if (w != arg.w) return w < arg.w;
  12.         if (type != arg.type) return type < arg.type;
  13.         return c < arg.c;
  14.     }
  15. };
  16.  
  17. int main()
  18. {
  19.     ios_base::sync_with_stdio(false);
  20.     cin.tie(0);
  21.     cout.tie(0);
  22.     int n;
  23.     cin >> n;
  24.     vector<event> e;
  25.     int w, c;
  26.     for (int i = 0; i < n; i++) {
  27.         cin >> w >> c;
  28.         e.push_back((event(w, c, 0, i)));
  29.     }
  30.     int m;
  31.     cin >> m;
  32.     for (int i = 0; i < m; i++) {
  33.         cin >> w >> c;
  34.         e.push_back(event(w, c, 1, i));
  35.     }
  36.     sort(e.begin(), e.end());
  37.     set<pair<int, int>> av;
  38.     vector<int> ans(n, 0);
  39.     for (int i = e.size() - 1; i >= 0; i--) {
  40.         if (e[i].type == 1) {
  41.             av.insert({e[i].c, e[i].ind});
  42.         } else {
  43.             auto ke = av.lower_bound({e[i].c, 0});
  44.             if (ke != av.end()) {
  45.                 pair<int, int> kek = *ke;
  46.                 ans[e[i].ind] = kek.second;
  47.                 av.erase(ke);
  48.             } else {
  49.                 cout << -1;
  50.                 return 0;
  51.             }
  52.         }
  53.     }
  54.     for (int i = 0; i < n; i++) {
  55.         cout << ans[i] + 1 << " ";
  56.     }
  57. }
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