#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
vector<ll> arr, pre;
ll cost(ll k) {
ll mnco = 1e18;
for(int i=k; i<=n; i++) {
ll st = i-k+1, mid = st+(k+1)/2-1;
ll left = (arr[mid]*(mid-st+1))-(pre[mid]-pre[st-1]);
ll right = (pre[i]-pre[mid])-(arr[mid]*(i-mid));
mnco = min(mnco, left+right);
}
return mnco;
}
int besthub(int R, int L, int X[], long long B) {
n=R;
arr.assign(R+10, 0);
pre.assign(R+10, 0);
for(int i=1; i<=R; i++) {
arr[i] = X[i-1];
pre[i] = pre[i-1] + arr[i];
}
ll l=1, r=R;
while(l < r) {
ll mid = (l+r)/2;
if(cost(mid) > B) {
r = mid;
} else {
l = mid+1;
}
}
return l-1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |