#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
# define LL long long
long long ps[100100];
bool can( int k, LL b, int n, int a[] ) {
int j = k - 1;
for ( int i = 0; j < n; j++ ) {
int x = a[(i + j) / 2], m = (i + j) / 2;
LL sum = ps[m - 1];
if ( i ) {
sum -= ps[i - 1];
}
sum = (m - i) * x - sum;
LL sum1 = ps[j] - ps[m];
sum1 -= x * (j - m);
LL cnt = sum + sum1;
if ( cnt <= b ) {
return 1;
}
i++;
}
return 0;
}
int besthub(int n, int mx, int a[], long long b)
{
for ( int i = 0; i < n; i++ ) {
ps[i] = a[i];
if ( i ) {
ps[i] += ps[i - 1];
}
}
int l = 0, r = n, m, ans = 1;
while ( l <= r ) {
m = (l + r) / 2;
if ( can( m, b, n, a ) ) {
ans = m;
l = m + 1;
}
else {
r = m - 1;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
640 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
21 ms |
1536 KB |
Output is correct |
4 |
Correct |
21 ms |
1536 KB |
Output is correct |
5 |
Correct |
13 ms |
896 KB |
Output is correct |
6 |
Correct |
13 ms |
896 KB |
Output is correct |
7 |
Correct |
19 ms |
1536 KB |
Output is correct |
8 |
Correct |
19 ms |
1536 KB |
Output is correct |
9 |
Correct |
13 ms |
896 KB |
Output is correct |
10 |
Correct |
13 ms |
896 KB |
Output is correct |
11 |
Correct |
23 ms |
1536 KB |
Output is correct |
12 |
Correct |
27 ms |
1536 KB |
Output is correct |
13 |
Correct |
15 ms |
896 KB |
Output is correct |
14 |
Correct |
14 ms |
1280 KB |
Output is correct |
15 |
Correct |
18 ms |
2048 KB |
Output is correct |
16 |
Correct |
18 ms |
1920 KB |
Output is correct |
17 |
Correct |
21 ms |
2176 KB |
Output is correct |
18 |
Correct |
21 ms |
2088 KB |
Output is correct |
19 |
Correct |
22 ms |
2168 KB |
Output is correct |
20 |
Correct |
22 ms |
2176 KB |
Output is correct |