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;
using pii = pair<int, int>;
#define ff first
#define ss second
int A, B, T, *X, *Y, *W, *S;
pii P[1000005];
bool f(int m) {
priority_queue<int> pq;
int j = 0;
for (int i = 0; i < A; ++i) {
while (j < T && P[j].ff < X[i]) {
pq.push(P[j].ss);
j++;
}
for (int k = 0; pq.size() && k < m; ++k) pq.pop();
}
for (; j < T; ++j) pq.push(P[j].ss);
for (int i = B - 1; i >= 0; --i) {
for (int j = 0; pq.size() && j < m; ++j) {
if (pq.top() >= Y[i]) return 0;
pq.pop();
}
}
return pq.size() == 0;
}
int putaway(int AA, int BB, int TT, int XX[], int YY[], int WW[], int SS[]) {
A = AA, B = BB, T = TT, X = XX, Y = YY, W = WW, S = SS;
sort(X, X + A);
sort(Y, Y + B);
for (int i = 0; i < T; ++i)
if (W[i] >= X[A - 1] && S[i] >= Y[B - 1]) return -1;
for (int i = 0; i < T; ++i) P[i] = {W[i], S[i]};
sort(P, P + T);
int l = 1, r = T;
while (l < r) {
int m = l + r >> 1;
if (f(m)) r = m;
else l = m + 1;
}
return l;
}
Compilation message (stderr)
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:41:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# | 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... |