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 = 50004;
const int T = 1000006;
int x[T], y[T];
int w[T], s[T];
int putaway(int A, int B, int T_, int X[], int Y[], int W[], int S[]) {
int a, b, t;
a = A;
b = B;
t = T_;
for (int i = 0; i < a; ++i) {
x[i] = X[i];
}
sort(x, x + a);
for (int i = 0; i < b; ++i) {
y[i] = Y[i];
}
sort(y, y + b);
for (int i = 0; i < t; ++i) {
w[i] = W[i], s[i] = S[i];
}
vector<pair<int, int>> toy(t);
for (int i = 0; i < t; ++i) {
toy[i] = {w[i], s[i]};
}
sort(toy.begin(), toy.end(), greater<pair<int, int>>());
auto ch = [&](int mid) {
multiset<int> se;
for (int i = b - 1; i >= 0; --i) {
for (int j = 0; j < mid; ++j) {
se.insert(y[i]);
if (se.size() == T) {
break;
}
}
}
vector<bool> done(t);
for (int i = 0; i < t; ++i) {
auto it = se.upper_bound(toy[i].second);
if (it != se.end()) {
se.erase(it);
done[i] = true;
}
}
se.clear();
//cout << mid << '\n';
//for (int i = 0; i < t; ++i) {
//cout << done[i] << " \n"[i == t - 1];
//}
for (int i = a - 1; i >= 0; --i) {
for (int j = 0; j < mid; ++j) {
se.insert(x[i]);
if (se.size() == T) {
break;
}
}
}
for (int i = 0; i < t; ++i) {
auto it = se.upper_bound(toy[i].first);
if (done[i]) continue;
if (it != se.end()) {
se.erase(it);
done[i] = true;
}
}
bool ok = true;
for (int i = 0; i < t; ++i) {
ok &= done[i];
}
return ok;
};
int l = 1, r = t + 1;
while (l < r) {
int mid = (l + r) >> 1;
if (ch(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
return (l == t + 1 ? -1 : l);
}
# | 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... |