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<tuple<int, int, int>> sortedX(T), sortedY(T);
for (int i = 0; i < T; ++i) {
sortedX[i] = make_tuple(W[i], S[i], i);
sortedY[i] = make_tuple(W[i], S[i], i);
}
sort(sortedX.begin(), sortedX.end());
sort(sortedY.begin(), sortedY.end(), [&](const tuple<int, int, int> &x, const tuple<int, int, int> &y) {
return get<1>(x) < get<1>(y);
});
auto check = [&](const int &m) -> int {
vector<bool> taken(T);
priority_queue<pair<int, int>> pq;
int p = 0;
for (int i = 0; i < A; ++i) {
while (p < T && get<0>(sortedX[p]) < X[i]) {
pq.emplace(get<1>(sortedX[p]), get<2>(sortedX[p]));
p += 1;
}
int cnt = 0;
while (!pq.empty() && cnt < m) {
taken[pq.top().second] = true;
cnt += 1;
pq.pop();
}
}
p = 0;
vector<int> q;
for (int i = 0; i < B; ++i) {
while (p < T && get<1>(sortedY[p]) < Y[i]) {
if (!taken[get<2>(sortedY[p])]) {
q.emplace_back(get<2>(sortedY[p]));
}
p += 1;
}
int cnt = 0;
while (!q.empty() && cnt < m) {
taken[q.back()] = true;
cnt += 1;
q.pop_back();
}
}
for (int i = 0; i < T; ++i) {
if (!taken[i]) {
return false;
}
}
return true;
};
int l = 1, r = T, ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
return ans;
}
# | 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... |