This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef __APPLE__
#include "robots.h"
#endif
#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
std::sort(X, X + A);
std::sort(Y, Y + B);
Vec<Vec<int>> memo(A + 1);
for (int i = 0; i < T; ++i) {
const auto x = std::upper_bound(X, X + A, W[i]) - X;
const auto y = std::upper_bound(Y, Y + B, S[i]) - Y;
if (x == A && y == B) {
return -1;
}
memo[x].push_back(y);
}
int ok = T, ng = 0;
while (ok - ng > 1) {
const auto md = (ok + ng) / 2;
std::priority_queue<int> que;
for (int i = 0; i < A; ++i) {
for (const auto y: memo[i]) {
que.push(y);
}
for (int i = 0; i < md; ++i) {
if (que.empty()) {
break;
}
que.pop();
}
}
for (const auto y: memo[A]) {
que.push(y);
}
Vec<int> count(B + 1);
while (!que.empty()) {
count[que.top()] += 1;
que.pop();
}
long long cur = 0;
bool f = true;
for (int i = B; i >= 0; i--) {
cur += count[i];
if (cur > 0) {
f = false;
break;
}
cur -= md;
}
(f ? ok : ng) = md;
}
return ok;
}
#ifdef __APPLE__
int X[100];
int Y[100];
int W[100];
int S[100];
int main() {
int A, B, T;
std::cin >> A >> B >> T;
for (int i = 0; i < A; ++i) {
std::cin >> X[i];
}
for (int i = 0; i < B; ++i) {
std::cin >> Y[i];
}
for (int i = 0; i < T; ++i) {
std::cin >> W[i] >> S[i];
}
std::cout << putaway(A, B, T, X, Y, W, S) << '\n';
}
#endif
# | 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... |