This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx2,avx,sse3,sse4")
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
//if (A < B) { swap(A, B); swap(X, Y); swap(W, S); }
sort(X, X+A);
sort(Y, Y+B);
vector<pair<int, int>> v;
for (int i = 0; i < T; i++)
v.push_back({W[i], S[i]});
sort(v.begin(), v.end());
for (int i = 0; i < T; i++) {
W[i] = v[i].first, S[i] = v[i].second;
if (A && B) if (W[i] >= X[A-1] && S[i] >= Y[B-1])
return -1;
if (A && !B) if (W[i] >= X[A-1])
return -1;
if (!A && B) if (S[i] >= Y[B-1])
return -1;
}
int l = 1, r = T;
while (l < r) {
const int mid = (l+r)/2;
bool ok = true;
int idx = 0;
priority_queue<int> pq;
for (int i = 0; idx < T && i < A; i++) {
while (idx < T && W[idx] < X[i]) {
pq.push(S[idx]);
idx++;
}
for (int j = 0; pq.size() && j < mid; j++)
pq.pop();
}
while (idx < T) {
pq.push(S[idx]);
idx++;
}
for (int i = B-1; pq.size() && i >= 0; i--) {
for (int j = 0; pq.size() && j < mid; j++) {
if (pq.top() < Y[i])
pq.pop();
else break;
}
}
if (pq.empty())
r = mid;
else
l = mid+1;
}
return l;
}
Compilation message (stderr)
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:29:14: warning: unused variable 'ok' [-Wunused-variable]
29 | bool ok = true;
| ^~
# | 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... |