# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552492 | Sharky | Rice Hub (IOI11_ricehub) | 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 "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 100005
int r, l, b;
vector<int> v;
vector<int> ps(N, 0);
bool ok(int L, int R, int x) {
int mid = (L + R) >> 1; // median
// brute force
int cost = v[mid] * (mid - L + 1) - (ps[mid] - ps[L - 1]);
// cout << L << " " << R << " " << mid << " " << cost;
cost += (ps[R] - ps[mid]) - v[mid] * (R - mid);
// cout << " " << cost << "\n";
return (cost <= b);
}
bool check(int x) {
// x consecutive hubs
for (int i = 1; i <= r - x + 1; i++) {
if (ok(i, i + x - 1, x)) return true;
}
return false;
}
int besthub(int rr, int ll, int vv[], long long bb) {
v.push_back(0);
r = rr, l = ll, b = bb;
for (int i = 0; i < vv.size(); i++) { v.push_back(vv[i]); }
int lo = 1, hi = r, ans;
while (lo <= hi) {
int m = (lo + hi) >> 1;
// cout << m << " " << check(m) << "\n";
if (check(m)) lo = m + 1, ans = m;
else hi = m - 1;
}
return ans;
}