# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
494004 | TeaTime | 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 "robots.h"
typedef long long ll;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
ll mx = 1e6 + 100;
int l = 0, r = mx;
while (r - l > 1) {
int mid = (l + r) / 2;
vector<pair<int, int>> vec;
vector<int> skip(T);
for (int i = 0; i < T; i++) vec.push_back({ W[i], S[i] });
map<int, int> st;
vector<ll> svd;
for (int i = 0; i < A; i++) svd.push_back(X[i]);
reverse(svd.begin(), svd.end());
for (int i = 0; i < B; i++) {
st[Y[i]] += mid;
}
sort(vec.rbegin(), vec.rend());
for (int i = 0; i < T; i++) {
if (st.lower_bound(vec[i].second) != st.end()) {
ll x = (*st.lower_bound(vec[i].second)).first;
st[x]--;
skip[i] = 1;
if (st[x] == 0) st.erase(x);
}
}
ll pt = 0, pt2 = 0;
bool f = 1;
for (int i = 0; i < T; i++) {
if (skip[i]) continue;
if (svd.size() > pt && svd[pt] >= vec[i].first) {
pt2++;
if (pt2 == mid) {
pt2 = 0;
pt++;
}
} else {
f = 0;
break;
}
}
if (f) {
r = mid;
} else {
l = mid;
}
}
if (r == mx) {
return -1;
} else {
return r;
}
}