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 "teams.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int X = 700;
vector<pii> order, buckets[X];
#define r first
#define l second
void init(int N, int A[], int B[]) {
for (int i = 0; i < N; ++i) {
order.push_back({B[i], A[i]});
}
sort(order.begin(), order.end());
for (pii p: order) buckets[min(p.r,X-1)].push_back({p.r, p.l});
}
int can(int M, int K[]) {
int sm = accumulate(K, K+M, 0), lft = 0;
vector<int> ks(K, K+M);
sort(ks.begin(), ks.end(), greater<int>());
map<int, int> req;
if (sm < X) {
for (int r = 1; r < X; ++r) {
while (ks.size() && ks.back() <= r) {
lft = ks.back();
req[ks.back()] += ks.back();
ks.pop_back();
}
for (pii p: buckets[r]) {
if (p.l <= lft) {
auto it = req.lower_bound(p.l);
it->second--;
if (it->second == 0) req.erase(it);
lft = req.size() ? (--req.end())->first : 0;
} else break;
}
}
} else {
for (pii p: order) {
while (ks.size() && ks.back() <= p.r) {
lft = ks.back();
req[ks.back()] += ks.back();
ks.pop_back();
}
if (req.size() && p.l <= (--req.end())->first) {
if (p.l <= lft) {
auto it = req.lower_bound(p.l);
it->second--;
if (it->second == 0) req.erase(it);
lft = req.size() ? (--req.end())->first : 0;
} else break;
}
}
}
return req.size() == 0;
}
# | 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... |