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 "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=100010;
int X[MX], n, xmx;
ll S[MX];
ll _max(ll a, ll b){
return a>b ? a : b;
}
ll cost(int l, int r){
int mid=(l+r)/2;
ll leftsum = 1LL*X[mid]*(mid-l+1) - (S[mid]-S[l-1]);
ll rigtsum = (S[r]-S[mid]) - 1LL*X[mid]*(r-mid);
return leftsum+rigtsum;
}
ll solve(ll maxCost){
ll ans=0;
for(int l=1, r=1; l<=n; l++){
r=max(r,l);
while(r<n && cost(l,r+1)<=maxCost) r++;
if(cost(l,r)>maxCost) continue;
ans=_max(ans, 0LL+r-l+1);
}
return ans;
}
int besthub(int R, int L, int XX[], ll B) {
n=R, xmx=L;
for(int i=1; i<=n; i++){
X[i]=XX[i-1];
S[i]=S[i-1]+X[i];
}
return solve(B);
}
# | 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... |