This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "ricehub.h"
int n;
VI a;
VL pref;
ll B;
ll sum(int l, int r) {
return pref[r+1] - pref[l];
}
ll left(int i, int c) {
if (i-c+1 < 0) return 1e18;
return 1ll*c*a[i] - sum(i-c+1, i);
}
ll right(int i, int c) {
if (i+c-1 >= n) return 1e18;
return sum(i, i+c-1) - 1ll*c*a[i];
}
ll costodd(int i, int c) {
return left(i, c) + right(i, c);
}
ll costeven(int i, int c) {
if (i == n-1) return 1e18;
return left(i, c) + 1ll*c*(a[i+1]-a[i]) + right(i+1, c);
}
/*maximum x such that func(x) <= lim*/
int binsearch(function<ll(int)> func, int dl, int dr, ll lim) {
int l = dl-1;
int r = dr+1;
while (l + 1 < r) {
int m = (l + r) / 2;
if (func(m) <= lim) l = m;
else r = m;
}
return l;
}
int besthub(int R, int L, int X[], ll BVAL) {
n = R;
a = VI(n);
B = BVAL;
rep(i, n) a[i] = X[i];
pref = VL(n+1);
replr(i, 1, n) pref[i] = pref[i-1] + a[i-1];
int ans = 0;
rep(i, n) {
/*cout << i << ": ";*/
function<ll(int)> func1 = [&](int x){return costodd(i, x);};
function<ll(int)> func2 = [&](int x){return costeven(i, x);};
int oddans = binsearch(func1, 1, 2e5, B);
int evenans = binsearch(func2, 1, 2e5, B);
setmax(ans, oddans*2-1);
setmax(ans, evenans*2);
/*cout << oddans*2-1 << " " << evenans*2 << endl;*/
}
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... |