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;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1e5 + 10;
ll y[N];
int besthub(int n, int L, int x[], ll B) {
y[0] = x[0];
for(int i = 1; i < n; i++) {
y[i] = y[i - 1] + x[i];
}
auto cost = [&x](int l, int r) {
int m = l + r >> 1;
ll a = (ll) x[m] * (m - l + 1);
a -= y[m];
if(l) a += y[l - 1];
ll b = y[r] - y[m] - (r - m) * 1ll * x[m];
return a + b;
};
int l = 0, r = 0;
int ans = 0;
while(l < n) {
while(r < n && cost(l, r) <= B) r++;
ans = max(ans, r - l);
l++;
} return ans;
}
Compilation message (stderr)
ricehub.cpp: In lambda function:
ricehub.cpp:16:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# | 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... |