#include<bits/stdc++.h>
#include "ricehub.h"
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pb push_back
#define p_b pop_back
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
ll n = R, i;
ll h[n+5], pref[n+5];
pref[0] = 0;
for(i = 1; i <= n; i++)
h[i] = X[i-1];
for(i = 1; i <= n; i++)
pref[i] = pref[i-1] + h[i];
ll res = 0;
for(i = 1; i <= n; i++)
{
ll l = i, r = n, ans = i;
//cout << "i: " << i << "\n";
while(l <= r)
{
ll mid = (l + r) / 2;
ll rh = (h[mid] + h[i]) / 2;
ll tl = i, tr = mid, ok = i;
//cout << "mid: " << mid << " rh: " << rh << " tmid: ";
while(tl <= tr)
{
ll tmid = (tl + tr) / 2;
if(h[tmid] > rh)
tr = tmid - 1;
else{
ok = max(ok, tmid);
tl = tmid + 1;
}
}
ll tmid = ok;
//cout << tmid << " sum1: ";
ll sum1 = rh * (tmid - i + 1) - (pref[tmid] - pref[i-1]);
ll sum2 = pref[mid] - pref[tmid] - (mid - tmid) * rh;
ll sum = sum1 + sum2;
//cout << sum1 << " sum2: " << sum2 << " sum: " << sum << "\n";
if(sum > B)
r = mid - 1;
else
{
ans = max(ans, mid);
l = mid + 1;
}
}
res = max(res, ans - i + 1);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
448 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
960 KB |
Output is correct |
2 |
Correct |
3 ms |
964 KB |
Output is correct |
3 |
Correct |
27 ms |
3360 KB |
Output is correct |
4 |
Correct |
28 ms |
3420 KB |
Output is correct |
5 |
Correct |
22 ms |
1624 KB |
Output is correct |
6 |
Correct |
20 ms |
1624 KB |
Output is correct |
7 |
Correct |
47 ms |
3164 KB |
Output is correct |
8 |
Correct |
53 ms |
3152 KB |
Output is correct |
9 |
Correct |
26 ms |
1628 KB |
Output is correct |
10 |
Correct |
26 ms |
1628 KB |
Output is correct |
11 |
Correct |
52 ms |
3416 KB |
Output is correct |
12 |
Correct |
55 ms |
3420 KB |
Output is correct |
13 |
Correct |
24 ms |
1736 KB |
Output is correct |
14 |
Correct |
24 ms |
1800 KB |
Output is correct |
15 |
Correct |
42 ms |
2648 KB |
Output is correct |
16 |
Incorrect |
41 ms |
2652 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |