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;
long long besthub(int n,int l,int x[],long long b){
long long cost,ans=1;
int mid,en,low=0,high=n-1,m,check = 0;
vector<long long> prefixSum(n+1,0);
for(int i=1;i<=n;i++)prefixSum[i] = prefixSum[i-1]+x[i-1];
//for(int i=1;i<=n;i++)cout<<prefixSum[i]<<" "; cout<<endl;
while(low<=high){
m = (low+high)/2;
for(int st=0;st<n;st++){
en = st+m;
mid = (st+en)/2;
cost = (mid-st)*x[mid]*1LL-(prefixSum[mid]-prefixSum[st]) + (prefixSum[en+1]-prefixSum[mid+1])-(en-mid)*x[mid]*1LL;
if(cost <= b){
ans = max(ans,en-st+1LL);
check = 1;
}
//cout<<st<<" "<<en<<" "<<cost<<endl;
}
if(check)high = m-1;
else low = m+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... |