이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "robots.h"
typedef long long ll;
struct Toy {
ll w, s;
Toy(int W = 0, int S = 0) : w(W), s(S) { }
bool operator<(const Toy& other) const {
if (w == other.w) return s < other.s;
return w < other.w;
}
};
int putaway(int a, int b, int t, int X[], int Y[], int W[], int S[]) {
std::vector <int> x(a); for (int i = 0; i < a; i++) x[i] = X[i];
std::vector <int> y(b); for (int i = 0; i < b; i++) y[i] = Y[i];
std::vector <int> w(t); for (int i = 0; i < t; i++) w[i] = W[i];
std::vector <int> s(t); for (int i = 0; i < t; i++) s[i] = S[i];
std::vector <Toy> toy(t);
for (int i = 0; i < t; i++) toy[i] = Toy(w[i], s[i]);
std::sort(toy.begin(), toy.end());
std::sort(x.begin(), x.end());
std::sort(y.rbegin(), y.rend());
ll l = 1, r = t + 1;
while (l < r) {
ll mid = (l + r) >> 1LL, toys = 0;
std::priority_queue <ll> pq;
for (int i = 0; i < a; i++) {
while (toys < t && toy[toys].w < x[i])
pq.push(toy[toys].s), toys++;
ll tmp = mid;
while (pq.size() && tmp--) pq.pop();
}
while (toys < t) pq.push(toy[toys].s), toys++;
bool brk = false;
for (int i = 0; i < b; i++) {
ll tmp = mid;
while (pq.size() && tmp--) {
if (pq.top() >= y[i]) {
l = mid + 1LL;
brk = true; break;
}
pq.pop();
}
if (brk) break;
}
if (brk) continue;
if (pq.empty()) r = mid;
else l = mid + 1LL;
}
if (l == t + 1) return -1;
return 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... |