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;
const int N = 1e6;
int arrIndex[N + 5];
bool vis[N + 5];
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
sort(X, X + A);
sort(Y, Y + B, greater<int>());
iota(arrIndex, arrIndex + T, 0);
int l = 1, r = T, ans = T + 1;
while (l <= r) {
int m = (l + r)/2;
sort(arrIndex, arrIndex + T, [&](const int a, const int b) { return pair<int, int>(W[a], S[a]) < pair<int, int>(W[b], S[b]); });
priority_queue<pair<int, int>> pq;
memset(vis, false, sizeof(vis));
int index = 0;
for (int i = 0; i < A; i++) {
while (index < T && W[arrIndex[index]] < X[i]) pq.push({S[arrIndex[index]], arrIndex[index]}), index++;
int sz = pq.size();
for (int j = 0; j < min(sz, m); j++) {
int index = pq.top().second; pq.pop();
vis[index] = true;
}
}
pq = priority_queue<pair<int, int>>();
for (int i = 0; i < T; i++) {
if (!vis[arrIndex[i]]){
pq.push({S[arrIndex[i]], arrIndex[i]});
}
}
for (int i = 0; i < B; i++) {
int sz = pq.size();
for (int j = 0; j < min(sz, m); j++) {
int v = pq.top().first, index = pq.top().second;;
if (v >= Y[i]) break;
vis[index] = true;
pq.pop();
}
}
bool valid = true;
for (int i = 0; i < T; i++) valid &= vis[i];
if (valid) ans = m, r = m - 1;
else l = m + 1;
}
return (ans == T + 1 ? -1 : ans);
}
/*#define MAX_A 50000
#define MAX_B 50000
#define MAX_T 500000
static int X[MAX_A];
static int Y[MAX_B];
static int W[MAX_T];
static int S[MAX_T];
signed main() {
int A, B, T;
cin >> A >> B >> T;
for (int i = 0; i < A; i++) cin >> X[i];
for (int i = 0; i < B; i++) cin >> Y[i];
for (int i = 0; i < T; i++) cin >> W[i] >> S[i];
int res = putaway(A, B, T, X, Y, W, S);
cout << res << '\n';
}*/
# | 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... |