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 "robots.h"
#include <bits/stdc++.h>
using namespace std;
#define ar array
const int INF = 1e9+9;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
ar<int,2> toy[T];
for (int i = 0; i < T; i++) toy[i] = {W[i], S[i]};
sort(toy, toy + T); sort(X, X + A); sort(Y, Y + B);
auto check = [&](int remdi) {
priority_queue<int> pq;
// choose as many toys u can with max S, and move out with X
int j = 0;
for (int i = 0; i < A; i++) {
for (; j < T && toy[j][0] < X[i]; j++) pq.push(toy[j][1]);
for (int r = 0; r < remdi && !pq.empty(); r++) pq.pop();
}
// add in remaining toys
for (; j < T; j++) pq.push(toy[j][1]);
// use Y bots to move out
for (int i = B - 1; i >= 0; i--)
for (int r = 0; r < remdi && !pq.empty() && pq.top() < Y[i]; r++)
pq.pop();
return pq.empty();
};
int ans = INF, lo = 0, hi = T, mid;
while (lo <= hi) {
mid = (lo + hi) >> 1;
if (check(mid)) hi = mid - 1, ans = mid;
else lo = mid + 1;
}
return ans == INF ? -1 : 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... |