#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
ll pref[100001], x[100000];
ll sum(int l, int r)
{
return pref[r + 1] - pref[l];
}
ll cost(int l, int r, int i)
{
return sum(i + 1, r) + x[i] * (2 * i - l - r) - sum(l, i - 1);
}
ll find_min(int l, int r)
{
int x = l;
for (int k = 25; k >= 0; k--)
if (x + (1 << k) <= r && cost(l, r, x + (1 << k)) <= cost(l, r, x))
x += (1 << k);
return cost(l, r, x);
}
ll calc(int R, int X[], int cnt)
{
ll mn = LLONG_MAX;
for (int l = 0, r = cnt - 1; r < R; l++, r++)
mn = min(mn, find_min(l, r));
return mn;
}
int besthub(int R, int L, int X[], ll B)
{
for (int i = 0; i < R; i++)
x[i] = X[i], pref[i + 1] = pref[i] + X[i];
int lo = 0, hi = R;
while (lo < hi)
{
int mid = (lo + hi + 1) / 2;
if (calc(R, X, mid) <= B)
lo = mid;
else hi = mid - 1;
}
return lo;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |