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];
}
for (int i = 0; i < b; ++i) {
y[i] = Y[i];
}
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) {
set<pair<int, int>> sx;
set<pair<int, int>> se;
for (int i = 0; i < b; ++i) {
se.emplace(y[i], mid);
}
for (int i = 0; i < a; ++i) {
sx.emplace(x[i], mid);
}
for (int i = 0; i < t; ++i) {
pair<int, int> pp = make_pair(toy[i].second, 0);
auto it = se.upper_bound(pp);
if (it != se.end()) {
auto it2 = *it;
se.erase(it);
it2.second--;
if (it2.second != 0) {
se.emplace(it2);
}
} else {
pp = make_pair(toy[i].first, 0);
it = sx.upper_bound(pp);
if (it == sx.end()) {
return false;
}
sx.erase(it);
auto it2 = *it;
it2.second--;
if (it2.second) {
sx.emplace(it2);
}
}
}
return true;
};
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... |