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;
typedef long long ll;
ll n,x[100005],k,s[100005];
bool check(int m){
ll l=1,r=m;
for(ll i=1;i<=n;i++){
while(abs(x[r+1]-x[i])<abs(x[i]-x[l]))l++,r++;
if((s[r]-s[i])-(r-i)*x[i]+(i-l+1)*x[i]-(s[i]-s[l-1])<=k)return true;
}
return false;
}
int besthub(int R,int L,int*X,ll B){
n=R,k=B;
for(int i=1;i<=n;i++)x[i]=X[i-1],s[i]+=s[i-1],s[i]+=x[i];
x[n+1]=2000000000;
int l=1,r=n+1;
while(r-l>1){
int m=(l+r)/2;
if(check(m))l=m;
else r=m;
}
return l;
}
# | 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... |