#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1000000007;
int besthub(int r, int l, int x[], ll b){
ll ans=0,n,m,cnt,temp;
forp(i,0,r-1){
n=i-1,m=i+1;
cnt=1,temp=0;
while(temp<=b){
if(n<0 && m>r-1){
break;
} else if(n>=0 && m>r-1){
if(temp+(x[i]-x[n])<=b){
temp+=(x[i]-x[n]);
n--;
cnt++;
} else {
break;
}
} else if(m<=r-1 && n<0){
if(temp+(x[m]-x[i])<=b){
temp+=(x[m]-x[i]);
m++;
cnt++;
} else {
break;
}
} else {
if(x[m]-x[i]<x[i]-x[n] && temp+(x[m]-x[i])<=b){
temp+=(x[m]-x[i]);
m++;
cnt++;
} else if(temp+(x[i]-x[n])<=b){
temp+=(x[i]-x[n]);
n--;
cnt++;
} else {
break;
}
}
}
ans=max(ans,cnt);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
2 ms |
308 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
3 ms |
204 KB |
Output is correct |
18 |
Correct |
3 ms |
312 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
45 ms |
340 KB |
Output is correct |
24 |
Correct |
42 ms |
472 KB |
Output is correct |
25 |
Correct |
85 ms |
356 KB |
Output is correct |
26 |
Correct |
83 ms |
332 KB |
Output is correct |
27 |
Correct |
22 ms |
356 KB |
Output is correct |
28 |
Correct |
22 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
588 KB |
Output is correct |
2 |
Correct |
5 ms |
520 KB |
Output is correct |
3 |
Execution timed out |
1094 ms |
1740 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |