#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
const long long INF = 1e18;
vector< long long > pref;
long long calc(int left, int right, long long B, int X[]){
long long l = left, r = right;
while(l < r){
long long mid = (l+r+1)/2;
long long k = (left+mid)/2;
long long cost = X[k-1]*(k-left+1)-(pref[k]-pref[left-1])+(pref[mid]-pref[k])-(mid-k)*X[k-1];
if(cost > B){
r = mid-1;
}else{
l = mid;
}
}
return l-left+1;
}
int besthub(int R, int L, int X[], long long B){
pref.resize(R+1);
for(int i = 0; i < R; i++){
pref[i+1] += pref[i];
pref[i+1] += X[i];
}
long long ans = -INF;
for(int i = 1; i <= R; i++){
ans = max(calc(i,R,B,X), ans);
}
return ans;
}
/*
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int r, l, b;
cin >> r >> l >> b;
int x[r];
for(int i = 0; i < r; i++) cin >> x[i];
cout << besthub(r,l,x,b) << endl;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
512 KB |
Output is correct |
25 |
Correct |
3 ms |
412 KB |
Output is correct |
26 |
Correct |
3 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
37 ms |
1536 KB |
Output is correct |
4 |
Correct |
24 ms |
1528 KB |
Output is correct |
5 |
Correct |
19 ms |
1280 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
19 ms |
2304 KB |
Output is correct |
8 |
Correct |
33 ms |
2304 KB |
Output is correct |
9 |
Correct |
11 ms |
1152 KB |
Output is correct |
10 |
Correct |
18 ms |
1152 KB |
Output is correct |
11 |
Correct |
39 ms |
2560 KB |
Output is correct |
12 |
Correct |
31 ms |
2552 KB |
Output is correct |
13 |
Correct |
12 ms |
1280 KB |
Output is correct |
14 |
Correct |
11 ms |
1408 KB |
Output is correct |
15 |
Correct |
18 ms |
2048 KB |
Output is correct |
16 |
Correct |
19 ms |
2124 KB |
Output is correct |
17 |
Correct |
21 ms |
2432 KB |
Output is correct |
18 |
Correct |
22 ms |
2432 KB |
Output is correct |
19 |
Correct |
23 ms |
2560 KB |
Output is correct |
20 |
Correct |
23 ms |
2432 KB |
Output is correct |