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;
#define ll long long
ll besthub(int n, int L, int pos[], ll bud){
ll l,p,sm;
l=p=sm=0;
while(p<n-1 && sm+pos[p+1]-pos[0]<=bud){
p++;
sm+=pos[p]-pos[0];
}
ll mx=p+1;
for (ll i = 1; i<n; i++){
sm+=(ll)(pos[i]-pos[i-1])*(i-l);
sm-=(ll)(pos[i]-pos[i-1])*(p-i+1);
while(sm>bud && l<i){
sm-=pos[i]-pos[l];
l++;
}
while(p<n-1 && sm+pos[p+1]-pos[i]<=bud){
p++;
sm+=pos[p]-pos[i];
}
mx=max(mx,p-l+1);
while(l<i && p<n-1 && (pos[p+1]-pos[i])<(pos[i]-pos[l])){
sm-=pos[i]-pos[l];
l++;
while(p<n-1 && sm+pos[p+1]-pos[i]<=bud){
p++;
sm+=pos[p]-pos[i];
}
mx=max(mx,p-l+1);
}
mx=max(mx,p-l+1);
}
return mx;
}
# | 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... |