# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1270561 | BlockOG | Robots (IOI13_robots) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
// mrrrow meeow :3
// go play vivid/stasis now! https://vividstasis.gay
#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;
int ____init = [] {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
return 0;
}();
int xw[1000000];
int ys[1000000];
int ind[1000000];
bool check(int a, int b, int t, int x[], int y[], int c) {
priority_queue<pair<int, int>> s;
int j = 0;
fo(i, 0, a) {
while (j < t && i >= xw[ind[j]]) s.push({ys[ind[j]], j}), j++;
fo(_, 0, c) {
if (s.empty()) break;
s.pop();
}
}
while (j < t) s.push({ys[ind[j]], j}), j++;
vector<int> s2;
while (s.size()) {
auto [v, _] = s.top();
s.pop();
s2.pb(v);
}
reverse(be(s2));
of(i, 0, b) {
fo(_, 0, c) {
if (s2.empty()) return true;
if (i >= s2.back()) s2.pob();
else return false;
}
}
return s2.empty();
}
int putaway(int a, int b, int t, int x[], int y[], int w[], int s[]) {
sort(x, x + a);
sort(y, y + b);
fo(i, 0, t) {
xw[i] = ub(x, x + a, w[i]) - x;
ys[i] = ub(y, y + b, s[i]) - y;
ind[i] = i;
if (xw[i] >= a && ys[i] >= b) return -1;
}
sort(ind, ind + t, [](int a, int b) { return xw[a] < xw[b]; });
int l = 1, r = t;
while (l < r) {
int mid = (l + r) / 2;
if (check(a, b, t, x, y, mid)) r = mid;
else l = mid + 1;
}
return l;
}