#include "ricehub.h"
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 100, M = 4096 + 10, len = 21, inf = 1e18;
const ll mod = 1e9 + 7;
int besthub(int n, int mx, int x[], long long b)
{
int l = 1, r = n + 1;
while(r - l > 1){
int mid = (r + l) / 2, sred = mid/2, last = 0;
ll sum = 0;
bool can = false;
for(int i = 0; i < mid; i++){
sum += abs(x[sred] - x[i]);
}
if(sum <=b) can = true;
for(int i = mid + 1; i < n; i++){
sum -= abs(x[sred] - x[last]);
last++;
sum += (x[sred + 1] - x[sred]) * ((mid - 1) / 2);
sum -= (x[sred + 1] - x[sred]) * (mid / 2);
sred++;
sum += x[i] - x[sred];
if(sum <= b) can = true;
}
if(can) l = mid;
else r = mid;
}
return l;
}
//
// int main(){
// ios::sync_with_stdio(false);
// cin.tie(NULL);
// return 0;
// }
//
# | 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... |