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, int k[]) {
// sort(k + 1, k + m + 1);
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;
int *A = (int *)malloc(sizeof(int) * (unsigned int)N);
int *B = (int *)malloc(sizeof(int) * (unsigned int)N);
for(int i = 0; i < n; i++) cin >> A[i] >> B[i];
init(n, A, B);
int q; cin >> q;
while (q--) {
int m; cin >> m;
int *k = (int *)malloc(sizeof(int) * (unsigned int)m);
for(int i = 0; i < m; i++) cin >> k[i];
cout << can(m, k) << endl;
}
}
#endif // ngu
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |