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>
#include "robots.h"
using namespace std;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
sort(X, X + A), sort(Y, Y + B);
vector<int> ordW(T), ordS(T);
iota(ordW.begin(), ordW.end(), 0);
ordS = ordW;
sort(ordW.begin(), ordW.end(), [&](int i, int j) {
return W[i] < W[j];
});
sort(ordS.begin(), ordS.end(), [&](int i, int j) {
return S[i] < S[j];
});
auto check = [&](int mid) {
vector<bool> used(T);
int pnt = 0;
priority_queue<pair<int, int>> st;
for (int i = 0; i < A; ++i) {
while (pnt < T && W[ordW[pnt]] < X[i]) {
st.emplace(S[ordW[pnt]], pnt);
++pnt;
}
int cnt = 0;
while (cnt < mid && !st.empty()) {
int j = st.top().second;
st.pop();
cnt += !used[ordW[j]];
used[ordW[j]] = true;
}
}
pnt = 0;
for (int i = 0; i < B; ++i) {
int cnt = 0;
while (cnt < mid && pnt < T && S[ordS[pnt]] < Y[i]) {
cnt += !used[ordS[pnt]];
used[ordS[pnt]] = true;
++pnt;
}
}
return (*min_element(used.begin(), used.end())) == true;
};
for (int i = 0; i < T; ++i) {
if ((!A || X[A - 1] <= W[i]) && (!B || Y[B - 1] <= S[i])) {
return -1;
}
}
assert(check(T));
int lo = 0, hi = T;
while (lo + 1 < hi) {
int mid = (lo + hi) / 2;
if (check(mid)) {
hi = mid;
} else {
lo = mid;
}
}
return hi;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |