#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll,ll>
#define all(x) (x).begin(),(x).end()
vl sx,x;
ll b;
bool check(int tl, int tr) {
int mid=tl+(tr-tl)/2;
ll price=(mid-tl+1)*x[mid]-(sx[mid+1]-sx[tl])+(sx[tr+1]-sx[mid+1])-(tr-mid)*x[mid];
return (price<=b);
}
int besthub(int n, int l, int _x[], ll _b) {
b=_b;
sx.resize(n+1,0);
x.resize(n);
for (int i=0; i<n; i++) {
x[i]=_x[i];
sx[i+1]=sx[i]+x[i];
}
int ans=1;
int tl=0,tr=0;
while (tr<n-1) {
tr++;
while (!check(tl,tr)) {
tl++;
}
ans=max(ans,tr-tl+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... |