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>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;
ll a[1000005];
ll l[1000005];
bool can(int i, int j, ll b) {
int mid = (i+j)/2;
ll left = (mid-i+1)*a[mid] - (l[mid]-l[i-1]);
ll right = l[j]-l[mid-1] - (j-mid+1)*a[mid];
return left+right <= b;
}
ll besthub(int r, int L, int x[], ll b) {
int maxlen = -1;
for(int i = 0; i < r; i++) a[i+1] = x[i];
for(int i = 1; i <= r; i++) l[i] = l[i-1] + a[i];
int ptr = 1;
for(int i = 1; i <= r; i++) {
ptr = max(i, ptr);
while(ptr+1 <= r && can(i, ptr+1, b)) ptr++;
maxlen = max(maxlen, ptr-i+1);
}
return maxlen;
}
/*
int main()
{
int x[1] = {1};
cout << besthub(1, 20, x, 6) << endl;
return 0;
}*/
# | 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... |