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;
using ll = long long;
ll Pre[100005];
ll Sum(ll l, ll r) {
if ( l == 0) return Pre[r];
return Pre[r] - Pre[l - 1];
}
int besthub(int R, int L, int X[], long long B) {
ll s;
int i, ans = 0, mn, l, r,lo, hi, mid;
for (i = 0; i < R; i ++) {
if ( i == 0) Pre[i] = X[i];
else Pre[i] = Pre[i - 1] + X[i];
}
for (int i = 0; i + 1 < R; i ++) {
if ( X[i + 1] - X[i] > B) continue;
lo = 0;
hi = min(i + 1, R - (i + 1)) - 1;
while ( lo < hi ) {
mid = (lo +hi)/2;
l = i - mid;
r = i + mid + 1;
if ( Sum(i + 1, r) - Sum(l, i) <= B) lo = mid + 1;
else hi = mid;
}
mid = lo + 1 ;
l = i - mid + 1;
r = i + mid;
mn = INT_MAX;
if ( l >= 0) {
mn = min(mn, X[i] - X[l]);
}
if ( r < R) {
mn = min(mn, X[r] - X[i + 1]);
}
if (mn + s <= B) {
ans = max(ans, r - l);
}
else ans = max(ans, r - l - 1);
}
return ans;
}
Compilation message (stderr)
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:38:10: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
38 | if (mn + s <= B) {
| ~~~^~~
# | 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... |