#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include "ricehub.h"
using namespace std;
#define ALL(x) x.begin(), x.end()
#define N 100005
using ll = long long;
int n, l, z = -1;
ll b, p[N], a[N];
int optimal_hub(int l, int r)
{
return (l+r)/2;
}
ll sum(int l, int r)
{
return p[r] - p[l-1];
}
ll need_budget(int l, int r, int h)
{
if (h < l || r < h) return 1e18;
return a[h] * (h-l+1) - a[h] * (r-h) + sum(h+1, r) - sum(l, h);
}
ll need_budget(int l, int r)
{
return min({need_budget(l, r, optimal_hub(l, r)),
need_budget(l, r, optimal_hub(l, r) + 1),
need_budget(l, r, optimal_hub(l, r) - 1)});
}
int besthub(int r, int l, int *a, ll b)
{
for (int i = 1; i <= n; ++i)
{
p[i] = p[i-1] + a[i-1];
int l = 1, r = i;
while (l <= r)
{
int y = (l+r)/2;
if (need_budget(y, i) <= b)
z = max(z, i-y+1), r = y - 1;
else l = y + 1;
}
}
return z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |