#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int n, int l, int a[], long long b){
vector<long long> pref(n + 1);
for(int i = 1; i <= n; i ++)
pref[i] = pref[i - 1] + a[i - 1];
auto good = [&](int x){
for(int i = 0; i < n - x + 1; i ++){
long long middle = a[i + x / 2], sum = middle * (x / 2 + 1) - pref[i + x / 2 + 1] + pref[i] + pref[i + x] - pref[i + x / 2 + 1] - middle * (x - x / 2 - 1);
if(sum <= b)
return true;
}
return false;
};
int left = 1, right = n;
while(left < right){
int mid = (left + right + 1) >> 1;
if(good(mid))
left = mid;
else
right = mid - 1;
}
return left;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 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 |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 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 |
448 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
440 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
11 ms |
4448 KB |
Output is correct |
4 |
Correct |
13 ms |
4444 KB |
Output is correct |
5 |
Correct |
4 ms |
3164 KB |
Output is correct |
6 |
Correct |
5 ms |
3420 KB |
Output is correct |
7 |
Correct |
7 ms |
4216 KB |
Output is correct |
8 |
Correct |
8 ms |
4188 KB |
Output is correct |
9 |
Correct |
4 ms |
3164 KB |
Output is correct |
10 |
Correct |
6 ms |
3144 KB |
Output is correct |
11 |
Correct |
9 ms |
4440 KB |
Output is correct |
12 |
Correct |
8 ms |
4320 KB |
Output is correct |
13 |
Correct |
5 ms |
3420 KB |
Output is correct |
14 |
Correct |
4 ms |
3420 KB |
Output is correct |
15 |
Correct |
7 ms |
4028 KB |
Output is correct |
16 |
Correct |
7 ms |
3928 KB |
Output is correct |
17 |
Correct |
8 ms |
4180 KB |
Output is correct |
18 |
Correct |
8 ms |
4188 KB |
Output is correct |
19 |
Correct |
8 ms |
4324 KB |
Output is correct |
20 |
Correct |
8 ms |
4188 KB |
Output is correct |