#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define name "ricehub"
#define MAXN 100005
#define pb push_back
#define pf push_front
#define ll long long
#define ii pair<int, int>
#define fs first
#define sc second
#define ill pair<int, ll>
#define lli pair<ll, int>
#define llll pair<ll, ll>
#define all(v) v.begin(),v.end()
#define uni(v) v.erase(unique(all(v)),v.end())
#define bit(n,i) (((n)>>(i))&1)
#define FOR(i,a,b) for (int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for (int i=(a),_b=(b); i>=_b; i--)
#define MASK(i) (1LL<<(i))
const int INF=1e9;
const int MOD=1e9+7;
void add(int &u, int v){
u+=v;
if (u>=MOD) u-=MOD;
}
void sub(int &u, int v){
u-=v;
if (u<0) u+=MOD;
}
void minimize(int &u, int v){
u=min(u,v);
}
void maximize(int &u, int v){
u=max(u,v);
}
long long Rand(long long l, long long r){
ll tmp=0;
FOR(i,1,4) tmp=((tmp<<15)^(((1<<15)-1)&rand()));
return l+tmp%(r-l+1);
}
int n,LIM,a[MAXN];
ll b;
ll pre[MAXN];
ll get(int l, int r){
return pre[r]-pre[l-1];
}
bool check(int d){
FOR(i,1,n-d+1){
int l=i,r=i+d-1;
int mid=(l+r)/2;
ll cost=1LL*(mid-l+1)*a[mid]-get(l,mid)-1LL*a[mid]*(r-mid)+get(mid+1,r);
if (cost<=b) return 1;
}
return 0;
}
int solve(){
FOR(i,1,n) pre[i]=pre[i-1]+1LL*a[i];
int l=1,r=n,res=-1;
while (l<=r){
int mid=(l+r)/2;
if (check(mid)){
l=mid+1;
res=mid;
}
else r=mid-1;
}
return res;
}
int besthub(int R, int L, int X[], ll B){
n=R;
FOR(i,1,n) a[i]=X[i-1];
b=B;
LIM=L;
return solve();
}
# | 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... |