#include "ricehub.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
bool check(int k, ll B, vector<int>&arr){
ll cost = 0;
int n = arr.size(), p = (k-1) / 2;
for (int i = 0; i < k; i++)
cost += abs(arr[i] - arr[p]);
if (cost <= B)
return true;
for (int i = k; i < n; i++){
int y = arr[i], x = arr[i - k];
int m = arr[p], mp = arr[p+1];
p += 1;
if (k&1){
cost += y + x;
cost -= m + mp;
}
else{
cost += y + x;
cost -= mp + mp;
}
if (cost <= B)
return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B){
vector<int> arr;
for (int i = 0; i < R; i++)
arr.push_back(X[i]);
int st = 1, en = R;
while (st < en){
int mid = (st + en + 1) >> 1;
if (check(mid, B, arr))
st = mid;
else
en = mid - 1;
}
return st;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
4 ms |
596 KB |
Output is correct |
3 |
Correct |
10 ms |
1288 KB |
Output is correct |
4 |
Correct |
10 ms |
1348 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
8 ms |
852 KB |
Output is correct |
7 |
Correct |
9 ms |
1336 KB |
Output is correct |
8 |
Correct |
9 ms |
1260 KB |
Output is correct |
9 |
Correct |
5 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
11 ms |
1360 KB |
Output is correct |
12 |
Correct |
10 ms |
1360 KB |
Output is correct |
13 |
Correct |
5 ms |
852 KB |
Output is correct |
14 |
Correct |
5 ms |
852 KB |
Output is correct |
15 |
Correct |
8 ms |
2000 KB |
Output is correct |
16 |
Correct |
9 ms |
1956 KB |
Output is correct |
17 |
Correct |
10 ms |
2208 KB |
Output is correct |
18 |
Correct |
10 ms |
2240 KB |
Output is correct |
19 |
Correct |
10 ms |
2256 KB |
Output is correct |
20 |
Correct |
11 ms |
2256 KB |
Output is correct |