# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
305322 | Temmie | Robots (IOI13_robots) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
struct Toy {
int 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,
std::vector <int> x,
std::vector <int> y,
std::vector <int> w,
std::vector <int> s) {
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());
int l = 0, r = t + 1;
while (l < r) {
int mid = l + ((r - l) >> 1), toys = 0;
std::priority_queue <int> pq;
for (int i = 0; i < a; i++) {
while (toys < t && toy[pq.size()].w < x[i])
pq.push(toy[pq.size()].s), toys++;
int tmp = mid;
while (pq.size() && tmp--) pq.pop();
}
while (toys < t) pq.push(toy[pq.size()].s), toys++;
bool brk = false;
for (int i = 0; i < b; i++) {
int tmp = mid;
while (pq.size() && tmp--) {
if (pq.top() >= y[i]) {
l = mid + 1;
brk = true; break;
}
pq.pop();
}
if (brk) break;
}
if (brk) continue;
if (pq.empty()) r = mid;
else l = mid + 1;
}
if (l == t + 1) return -1;
return l;
}