Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct event {
- int w, c, type, ind; //0 - zerg 1 - axe
- event(int w, int c, int type, int ind):w(w), c(c), type(type), ind(ind){}
- bool operator <(const event& arg) const {
- if (w != arg.w) return w < arg.w;
- if (type != arg.type) return type < arg.type;
- return c < arg.c;
- }
- };
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- vector<event> e;
- int w, c;
- for (int i = 0; i < n; i++) {
- cin >> w >> c;
- e.push_back((event(w, c, 0, i)));
- }
- int m;
- cin >> m;
- for (int i = 0; i < m; i++) {
- cin >> w >> c;
- e.push_back(event(w, c, 1, i));
- }
- sort(e.begin(), e.end());
- set<pair<int, int>> av;
- vector<int> ans(n, 0);
- for (int i = e.size() - 1; i >= 0; i--) {
- if (e[i].type == 1) {
- av.insert({e[i].c, e[i].ind});
- } else {
- auto ke = av.lower_bound({e[i].c, 0});
- if (ke != av.end()) {
- pair<int, int> kek = *ke;
- ans[e[i].ind] = kek.second;
- av.erase(ke);
- } else {
- cout << -1;
- return 0;
- }
- }
- }
- for (int i = 0; i < n; i++) {
- cout << ans[i] + 1 << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement