# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1200607 | crispxx | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ar array
#define nl '\n'
#include "grader.cpp"
int besthub(int n, int l, int x[], long long B) {
vector<long long> pref(n + 1);
vector<long long> a(n + 1);
for(int i = 0; i < n; i++) {
a[i + 1] = x[i];
pref[i + 1] = pref[i] + x[i];
}
auto sum = [&](int l, int r) {
return pref[r] - pref[l - 1];
};
int ans = 0;
for(int i = 1; i <= n; i++) {
int l = i, r = n;
while(l < r) {
int mid = (l + r + 1) >> 1;
int j = (i + mid) >> 1;
long long cost = a[j] * (j - i) - sum(i, j - 1) + sum(j + 1, mid) - a[j] * (mid - j);
if(cost <= B) {
l = mid;
} else {
r = mid - 1;
}
}
ans = max(ans, r - i + 1);
}
return ans;
}