이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |