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
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
const int N = 1e6 + 10;
ll ps[N];
ll cost(int len, int n, int X[])
{
ll res = 1e18;
for (int l = 1; l <= n - len + 1; ++l)
{
int r = l + len - 1;
int mid = (l + r) / 2;
ll C = (ll)X[mid - 1] * (mid - l + 1) - ps[mid] + ps[l - 1] + ps[r] - ps[mid] - (ll)X[mid - 1] * (r - mid);
res = min(res, C);
}
return res;
}
int besthub(int n, int L, int X[], ll B)
{
for (int i = 1; i <= n; ++i) ps[i] = ps[i - 1] + X[i - 1];
int l = 1, r = n, ans = 1;
while (l <= r)
{
int mid = (l + r) / 2;
if (cost(mid, n, X) <= B) ans = mid, l = mid + 1;
else r = mid - 1;
}
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... |