이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |