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>
#include "ricehub.h"
using namespace std;
const int R = 1e5 + 5;
int xx[R];
long long s[R];
long long sum(int i, int j) {
if (i > j) {
return 0;
}
return (i == 0 ? s[j] : s[j] - s[i - 1]);
}
long long cost(int i, int j) {
int mid = (i + j) >> 1;
long long res = 0;
res += 1LL * xx[mid] * (mid - i + 1) - sum(i, mid);
if (mid + 1 <= j) {
res += sum(mid + 1, j) - 1LL * xx[mid] * (j - mid);
}
return res;
}
int besthub(int r, int l, int x[], long long b) {
for (int i = 0; i < r; i++) {
s[i] = (i == 0 ? x[i] : x[i] + s[i - 1]);
xx[i] = x[i];
}
int ans = 0;
for (int i = 0, j = 0; i < r; i++) {
while (j + 1 <= i && cost(j, i) > b) {
j++;
}
ans = max(ans, i - j + 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... |