#include <bits/stdc++.h>
#include "ricehub.h"
#define sz(s) (int)s.size()
using namespace std;
#define ll long long
vector <int> v;
bool f(int x, ll b, int n){
ll k = 0, ind = x/2, in = x-1;
for(int i = 0; i < in; i++){
k += abs(v[ind]-v[i]);
}
while(in < n){
k += abs(v[in]-v[ind]);
if(k <= b) return true;
k -= (in-ind)*(v[ind+1]-v[ind]);
k += (ind-(in-x+1))*(v[ind+1]-v[ind]);
k -= (v[ind]-v[in-x+1]);
in++;
ind++;
}
return false;
}
int besthub(int n, int L, int a[], ll b){
for(int i = 0; i < n; i++) v.push_back(a[i]);
int l = 2, r = n, ans = 1;
while(l <= r){
int md = (l + r) / 2;
if(f(md,b,n) == 1){
l = md+1;
ans = md;
}
else {
r = md-1;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
396 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 |
448 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 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 |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 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 |
460 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
12 ms |
2520 KB |
Output is correct |
4 |
Correct |
9 ms |
2368 KB |
Output is correct |
5 |
Correct |
5 ms |
1372 KB |
Output is correct |
6 |
Correct |
4 ms |
1372 KB |
Output is correct |
7 |
Correct |
8 ms |
2264 KB |
Output is correct |
8 |
Correct |
8 ms |
2264 KB |
Output is correct |
9 |
Correct |
6 ms |
1372 KB |
Output is correct |
10 |
Correct |
5 ms |
1240 KB |
Output is correct |
11 |
Correct |
10 ms |
2520 KB |
Output is correct |
12 |
Correct |
10 ms |
2520 KB |
Output is correct |
13 |
Correct |
5 ms |
1240 KB |
Output is correct |
14 |
Correct |
5 ms |
1372 KB |
Output is correct |
15 |
Correct |
6 ms |
2008 KB |
Output is correct |
16 |
Correct |
6 ms |
2156 KB |
Output is correct |
17 |
Correct |
7 ms |
2264 KB |
Output is correct |
18 |
Correct |
8 ms |
2364 KB |
Output is correct |
19 |
Correct |
8 ms |
2264 KB |
Output is correct |
20 |
Correct |
9 ms |
2264 KB |
Output is correct |