#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#include "ricehub.h"
ll N;
vector<ll> ps;
vector<ll> V;
ll cost(ll l, ll r) {
ll m = (l + r) / 2; // 0 indexed
// sum of the distance of coordinates between rice field m and rice fields [l, r]
return (ps[r+1] - ps[m+1]) - V[m] * (r-m) + V[m] * (m-l+1) - (ps[m+1] - ps[l]);
}
int besthub(int R, int L, int X[], ll B) {
::N = R;
ps.resize(N+1);
V.resize(N+1);
FOR(i,N) {ps[i+1] = ps[i] + X[i]; V[i] = X[i];}
ll res = 0, l = 0;
for (ll r = 0; r < N; r++) { // two pointers, indices of the ricehubs
ll c = cost(l, r);
while (c > B) {
l++;
c = cost(l, r);
}
res = max(res, r - l + 1);
}
return res;
}
# | 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... |