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>
using namespace std;
using ll = long long;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
const int N = 1e5+5;
ll n, budget;
ll pref[N];
ll calc(int l, int r){
int mid = (l+r)>>1;
ll valMid = pref[mid] - pref[mid-1];
ll prefixLmid = valMid * (1ll * (mid - l+1)) - (pref[mid] - pref[l-1]);
ll prefixmidR = (pref[r] - pref[mid]) - valMid * (1ll * (r - mid));
return prefixLmid + prefixmidR;
}
bool ok(int l, int r){
return calc(l, r) <= budget;
}
int besthub(int R, int L, int x[], ll B)
{
n = R, budget = B;
for(int i = 1; i <= n; i++){
pref[i] = pref[i-1] + 1ll * x[i-1];
}
int pointer = 1, answer = 0;
for(int i = 1; i <= n; i++){
while(pointer <= n && ok(i, pointer)) pointer++;
ckmx(answer, pointer - i);
}
return answer;
}
# | 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... |