#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int N, int L, int A[], long long B) {
int answer = 0, low = 0, high = N;
long long pref[N + 1];
pref[0] = 0;
for(int i = 1; i <= N; i++) pref[i] = pref[i - 1] + A[i - 1];
while(low < high) {
int mid = (low + high + 1) / 2;
bool possible = false;
for(int i = 0; i < N; i++) {
int start = i, end = i + mid;
if(end > N) break;
int hub = (start + 1 + end) / 2;
long long cost = abs((pref[hub] - pref[start]) - (long long) (hub - start) * A[hub - 1]);
cost += abs((pref[end] - pref[hub]) - (long long) (end - hub) * A[hub - 1]);
if(cost <= B) {
possible = true;
break;
}
}
if(possible) {
answer = max(answer, mid);
low = mid;
} else {
high = mid - 1;
}
}
return low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
492 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
3 |
Correct |
15 ms |
1516 KB |
Output is correct |
4 |
Correct |
15 ms |
1516 KB |
Output is correct |
5 |
Correct |
9 ms |
876 KB |
Output is correct |
6 |
Correct |
9 ms |
876 KB |
Output is correct |
7 |
Correct |
14 ms |
1516 KB |
Output is correct |
8 |
Correct |
13 ms |
1516 KB |
Output is correct |
9 |
Correct |
8 ms |
876 KB |
Output is correct |
10 |
Correct |
8 ms |
876 KB |
Output is correct |
11 |
Correct |
15 ms |
1516 KB |
Output is correct |
12 |
Correct |
15 ms |
1516 KB |
Output is correct |
13 |
Correct |
9 ms |
876 KB |
Output is correct |
14 |
Correct |
9 ms |
876 KB |
Output is correct |
15 |
Correct |
12 ms |
1132 KB |
Output is correct |
16 |
Correct |
11 ms |
1132 KB |
Output is correct |
17 |
Correct |
13 ms |
1388 KB |
Output is correct |
18 |
Correct |
16 ms |
1388 KB |
Output is correct |
19 |
Correct |
14 ms |
1388 KB |
Output is correct |
20 |
Correct |
24 ms |
1388 KB |
Output is correct |