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>
using namespace std;
#define ll long long int
ll psum(int i, int j, vector<ll> prefix) {
if (i > j) {
return 0;
}
if (i == 0) {
return prefix[j];
}
return prefix[j] - prefix[i - 1];
}
int besthub(int N, int L, int X[], ll B) {
vector<ll> prefix(N + 1);
prefix[0] = X[0];
for (int i = 1; i <= N; i++) {
prefix[i] = X[i] + prefix[i - 1];
}
int ans = 0;
for (int i = 0, j = 0; i < N; i++) {
while (j + 1 <= i) {
int mid = (i + j) / 2;
ll x = X[mid] * (mid - j + 1) - psum(j, mid, prefix);
if (mid + 1 <= i) {
x += psum(mid + 1, i, prefix) - X[mid] * (i - mid);
}
if (x <= B) {
break;
}
j++;
}
ans = max(ans, i - j + 1);
}
return ans;
}
// int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// int R, L;
// cin >> R >> L;
// int X[R];
// for (ll i = 0; i < R; i++) {
// cin >> X[i];
// }
// ll B;
// cin >> B;
// cout << besthub(R, L, X, B) << "\n";
// }
# | 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... |