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 <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
int besthub(int R, int L, int X[], long long B)
{
int n = R;
vector<ll> a(n+1);
for(int i = 1; i <= n; i++){
a[i] = X[i-1];
}
vector<ll> pf(n+2, 0);
for(int i = 1; i <= n; i++){
pf[i] = pf[i-1]+a[i];
}
auto check = [&](int x) -> bool{
for(int i = x; i <= n; i++){
int j = i-x+1;
int m = j+(x+1)/2-1;
ll left_cost = a[m]*(m-j+1) - (pf[m]-pf[j-1]);
ll right_cost = (pf[i]-pf[m]) - a[m]*(i-m);
ll cost = left_cost+right_cost;
if(cost <= B) return true;
}
return false;
};
int l = 0, r = n, mid;
while(l <= r){
mid = (l+r)/2;
if(check(mid)){
l = mid+1;
}else{
r = 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... |