# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885651 | nguyentunglam | Teams (IOI15_teams) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 1e5 + 10;
pair<int, int> a[N];
int n;
void init(int _n, int A[], int B[]) {
n = _n;
for(int i = 1; i <= n; i++) {
a[i] = make_pair(A[i - 1], B[i - 1]);
}
sort(a + 1, a + n + 1);
}
int can (int m, vector<int> k) {
priority_queue<int, vector<int>, greater<int> > q;
for(int i = 0, j = 1; i < m; i++) {
int x = k[i];
while (j <= n && a[j].first <= x) {
q.push(a[j].second);
j++;
}
int cnt = x;
while (!q.empty() && cnt > 0) {
int y = q.top(); q.pop();
if (y >= x) cnt--;
}
if (cnt) return 0;
}
return 1;
}
#ifdef ngu
int32_t main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n; cin >> n;
vector<int> x(n), y(n);
for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
init(n, x, y);
int q; cin >> q;
while (q--) {
int m; cin >> m;
vector<int> k(m);
for(int i = 0; i < m; i++) cin >> k[i];
cout << can(m, k) << endl;
}
}
#endif // ngu