#include<bits/stdc++.h>
using namespace std;
#include "ricehub.h"
int besthub(int R, int L, int X[], long long B){
long long ans = 1;
long long currsum = 0;
long long left = 0,right = -1;
for(long long i=0;i<R;i++){
currsum += (X[i]-X[i-1])*(i-left);
currsum -= (X[i]-X[i-1])*(right-i+1);
right = max(right,i);
while(currsum>B){
if(abs(X[i]-X[left])>abs(X[i]-X[right])){
currsum -= abs(X[i]-X[left]);
left++;
}
else{
currsum -= abs(X[i]-X[right]);
right--;
}
}
while(right!=R-1){
if(abs(X[i]-X[left])>abs(X[i]-X[right+1])){
currsum -= abs(X[i]-X[left]);
currsum += abs(X[i]-X[right+1]);
left++;
right++;
}
else{
break;
}
}
while(currsum<=B){
long long l,r;
if(left==0){
l = INT_MAX;
}
else{
l = abs(X[i]-X[left-1]);
}
if(right==R-1){
r = INT_MAX;
}
else{
r = abs(X[i]-X[right+1]);
}
long long mini = min(l,r);
if(currsum+mini>B||(l==INT_MAX&&r==INT_MAX)){
break;
}
if(l<r){
left--;
}
else{
right++;
}
currsum += mini;
}
ans = max(ans,right-left+1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
256 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
256 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
22 ms |
1024 KB |
Output is correct |
4 |
Correct |
22 ms |
1024 KB |
Output is correct |
5 |
Correct |
12 ms |
896 KB |
Output is correct |
6 |
Correct |
12 ms |
896 KB |
Output is correct |
7 |
Correct |
19 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1024 KB |
Output is correct |
9 |
Correct |
11 ms |
768 KB |
Output is correct |
10 |
Correct |
11 ms |
768 KB |
Output is correct |
11 |
Correct |
23 ms |
1024 KB |
Output is correct |
12 |
Correct |
25 ms |
1024 KB |
Output is correct |
13 |
Correct |
13 ms |
896 KB |
Output is correct |
14 |
Correct |
13 ms |
896 KB |
Output is correct |
15 |
Correct |
18 ms |
896 KB |
Output is correct |
16 |
Correct |
19 ms |
896 KB |
Output is correct |
17 |
Correct |
23 ms |
1024 KB |
Output is correct |
18 |
Correct |
22 ms |
1024 KB |
Output is correct |
19 |
Correct |
23 ms |
1024 KB |
Output is correct |
20 |
Correct |
23 ms |
1024 KB |
Output is correct |