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 <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int n; ll arr[N], sum[N], cap, lim;
ll calc(ll i, ll j, ll x) {
ll p = lower_bound(arr,arr+n,x) - arr; p++;
ll ret = x * (p - i) - (sum[p-1] - sum[i-1]);
ret = ret + sum[j] - sum[p-1] - x * (j - p + 1);
return ret;
}
bool ok(int l, int r) {
ll med = (sum[r] - sum[l-1]) / (r - l + 1);
for(ll i = max(0ll,med - 10); i <= min(med+10,lim); i++)
if(calc(l,r,i) <= cap) return true;
return false;
}
int besthub(int R, int L, int X[], ll B) {
n = R, cap = B, lim = L; sum[0] = 0;
for(int i = 0; i < R; i++) arr[i] = X[i];
for(int i = 1; i <= R; i++) sum[i] = sum[i-1] + X[i-1];
int r = 1, ans = 0;
for(int l = 1; l <= n; l++) {
while(r + 1 <= n && ok(l,r+1)) ++r;
if(ok(l,r)) ans = max(ans, r - l + 1);
}
return ans;
}
# | 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... |