#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 -= m + m;
}
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 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 |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
11 ms |
2368 KB |
Output is correct |
4 |
Correct |
11 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
1236 KB |
Output is correct |
6 |
Correct |
5 ms |
1236 KB |
Output is correct |
7 |
Correct |
14 ms |
2104 KB |
Output is correct |
8 |
Correct |
13 ms |
2116 KB |
Output is correct |
9 |
Correct |
5 ms |
1196 KB |
Output is correct |
10 |
Correct |
7 ms |
1108 KB |
Output is correct |
11 |
Correct |
11 ms |
2384 KB |
Output is correct |
12 |
Correct |
11 ms |
2384 KB |
Output is correct |
13 |
Correct |
5 ms |
1220 KB |
Output is correct |
14 |
Incorrect |
5 ms |
1236 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |