#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int besthub(int n, int maxCoordinate, int aArr[], ll budget) {
vector<int> a(n + 1); for (int i = 1; i <= n; i++) a[i] = aArr[i - 1]; int ans = 0;
vector<ll> p(n + 1); p[0] = 0; for (int i = 1; i <= n; i++) p[i] = a[i] + p[i - 1];
for (int l = 1; l <= n; l++) {
int low = l, high = n;
while (low <= high)
if (a[l + (((low + high) / 2) - l) / 2] * (2 * (l + (((low + high) / 2) - l) / 2) + 1 - l - ((low + high) / 2)) + (p[((low + high) / 2)] + p[l - 1] - 2 * p[l + (((low + high) / 2) - l) / 2]) <= budget) ans = max(ans, ((low + high) / 2) - l + 1), low = ((low + high) / 2) + 1;
else high = ((low + high) / 2) - 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... |