// #pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 998244353;
const ll inf = 1e18;
const ll blocksz = 320;
const ll N = 2e5+8;
int n;
ll a[N],b,l;
bool check(ll m){
ll suml = 0, sumr = 0, val_mid = 0;
ll lenl = (m+1)/2, lenr = m-lenl;
for(int i = 1; i <= (m+1)/2; i++) suml += a[i];
for(int i = (m+1)/2+1; i <= m; i++) sumr += a[i];
val_mid = a[(m+1)/2];
ll ans = inf;
for(int i = 1; i <= n-m+1; i++){
ans = min(ans,sumr-lenr*val_mid+val_mid*lenl-suml);
val_mid = a[(m+1)/2+i];
suml -= a[i], suml += val_mid;
sumr -= val_mid, sumr += a[i+m];
}
return (ans <= b);
}
int besthub(int R, int L, int X[], ll B){
n = R, l = L, b = B;
for(int i = 1; i <= n; i++) a[i] = X[i-1];
int l = 1, r = n;
int ans = 0;
while(l <= r){
ll m = l+r>>1;
if(check(m)){
ans = m;
l = m+1;
}
else r = m-1;
}
return ans;
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | ll m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
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 |
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 |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
452 KB |
Output is correct |
28 |
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 |
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 |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
356 KB |
Output is correct |
12 |
Correct |
0 ms |
356 KB |
Output is correct |
13 |
Correct |
0 ms |
444 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 |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
816 KB |
Output is correct |
3 |
Correct |
11 ms |
2680 KB |
Output is correct |
4 |
Correct |
9 ms |
2528 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
6 |
Correct |
4 ms |
1160 KB |
Output is correct |
7 |
Correct |
7 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
4 ms |
1324 KB |
Output is correct |
10 |
Correct |
4 ms |
1116 KB |
Output is correct |
11 |
Correct |
8 ms |
2652 KB |
Output is correct |
12 |
Correct |
8 ms |
2632 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
4 ms |
1372 KB |
Output is correct |
15 |
Correct |
6 ms |
2092 KB |
Output is correct |
16 |
Correct |
6 ms |
1884 KB |
Output is correct |
17 |
Correct |
7 ms |
2392 KB |
Output is correct |
18 |
Correct |
7 ms |
2396 KB |
Output is correct |
19 |
Correct |
7 ms |
2360 KB |
Output is correct |
20 |
Correct |
8 ms |
2396 KB |
Output is correct |