#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int low = 1;
int top = R;
int ns = 0;
while(low <= top){
ll mid = (low + top)/2;
ll mn = 1e18;
ll bel = 0;
ll aft = 0;
for(int i = 0; i < mid/2; i++){
bel += X[i];
}
for(int i = mid/2; i < mid; i++){
aft += X[i];
}
int mdl = mid/2;
int l = 0;
mn = min(mn, X[mdl]*(mid/2) - bel + aft - X[mdl]*((mid+1)/2));
for(int i = mid; i < R; i++){
bel -= X[l];
l++;
bel += X[mdl];
aft -= X[mdl];
mdl++;
aft += X[i];
mn = min(mn, X[mdl]*(mid/2) - bel + aft - X[mdl]*((mid+1)/2));
}
if(mn <= B){
low = mid+1;
ns = mid;
}else{
top = mid-1;
}
}
return ns;
}
| # | 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... |