# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223600 | staniewzki | Robots (IOI13_robots) | C++17 | 0 ms | 0 KiB |
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>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using PII = pair<int, int>;
#include "robots.h"
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<PII> pts(T);
REP(i, T) pts[i] = {W[i], S[i]};
sort(pts.begin(), pts.end());
auto check = [&](int q) {
priority_queue<int> Q;
int cur = 0;
REP(i, A + 1) {
while(cur < size(pts) && (i == A || pts[cur].ST < X[i]))
Q.emplace(pts[cur++].ND);
if(i != A) REP(j, q) {
if(Q.empty()) break;
Q.pop();
}
}
for(int i = B - 1; i >= 0; i--) {
REP(j, q) {
if(Q.empty()) break;
if(Q.top() >= Y[i]) return false;
Q.pop();
}
}
return Q.empty();
};
if(!check(T)) return -1;
int l = 1, r = T;
while(l < r) {
int m = (l + r) / 2;
if(check(m))
r = m;
else
l = m + 1;
}
return l;
}