#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
int besthub(int R, int L, int X[], long long B)
{
int n=R;
int ans=0;
for(int i=0;i<n;i++){
int l=i-1,r=i+1;
ll k=B;
int cnt=0;
while(1){
if(l==-1 and r==n)break;
if(l==-1){
if(abs(X[r]-X[i])<=k){
cnt++;
k-=abs(X[r]-X[i]);
r++;
}
else{break;}
}
else if(r==n){
if(abs(X[l]-X[i])<=k){
cnt++;
k-=abs(X[l]-X[i]);
l--;
}
else{break;}
}
else{
ll a=abs(X[r]-X[i]),b=abs(X[l]-X[i]);
if(a<=b){
if(abs(X[r]-X[i])<=k){
cnt++;
k-=abs(X[r]-X[i]);
r++;
}
else{break;}
}
else{
if(abs(X[l]-X[i])<=k){
cnt++;
k-=abs(X[l]-X[i]);
l--;
}
else{break;}
}
}
}
ans=max(ans,cnt);
}
return ans+1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
440 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 |
1 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 |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
428 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
344 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 |
352 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 |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
352 KB |
Output is correct |
22 |
Correct |
0 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
352 KB |
Output is correct |
26 |
Correct |
1 ms |
452 KB |
Output is correct |
27 |
Correct |
1 ms |
352 KB |
Output is correct |
28 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
356 KB |
Output is correct |
11 |
Correct |
1 ms |
448 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
360 KB |
Output is correct |
14 |
Correct |
2 ms |
356 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
3 ms |
352 KB |
Output is correct |
18 |
Correct |
2 ms |
456 KB |
Output is correct |
19 |
Correct |
4 ms |
348 KB |
Output is correct |
20 |
Correct |
4 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
484 KB |
Output is correct |
22 |
Correct |
5 ms |
480 KB |
Output is correct |
23 |
Correct |
39 ms |
348 KB |
Output is correct |
24 |
Correct |
36 ms |
488 KB |
Output is correct |
25 |
Correct |
90 ms |
492 KB |
Output is correct |
26 |
Correct |
86 ms |
344 KB |
Output is correct |
27 |
Correct |
22 ms |
344 KB |
Output is correct |
28 |
Correct |
24 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
604 KB |
Output is correct |
2 |
Correct |
5 ms |
604 KB |
Output is correct |
3 |
Execution timed out |
1093 ms |
1836 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |