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 FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
using namespace std;
int n;
vector<vector<int>> kub;
void init(int nn, int a[], int b[]){
n = nn;
kub.resize(n+1);
REP(i, n) kub[a[i]].emplace_back(b[i]);
}
int can(int m, int k[]){
vector<int> wym(n+1, 0);
REP(i, m) wym[k[i]] += k[i];
// wym ma 2sqrt(n) niezerowych wartosci
multiset<int> s;
FOR(i, 1, n){
for(int x : kub[i]) s.emplace(x);
while(s.size() && *s.begin() < i) s.erase(s.begin());
for(; wym[i]; --wym[i]){
if(s.empty()) return 0;
s.erase(s.begin());
}
}
return 1;
}
#ifdef LOCAL
#define maxn 1000
int main(){
int nn, a[maxn], b[maxn];
scanf("%d", &nn);
REP(i, nn) scanf("%d%d", &a[i], &b[i]);
init(nn, a, b);
int q;
scanf("%d", &q);
while(q--){
int m, k[maxn];
scanf("%d", &m);
REP(i, m) scanf("%d", &k[i]);
int wyn = can(m, k);
printf("%d\n", wyn);
}
}
#endif
# | 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... |