#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
long long int besthub(int r, int l, int a[], long long int b){
int j = (r/2) - 1, k = (r/2) + 1, i = r/2;
long long int budget = b, how_many = 1;
while(budget >= 0){
if(j < 0 and k >= r) break;
if(abs(a[j] - a[i]) <= abs(a[k] - a[i]) and abs(a[j] - a[i]) <= budget and j >= 0){
budget -= abs(a[j] - a[i]);
++how_many;
--j;
}
else if(abs(a[k] - a[i]) <= abs(a[j] - a[i]) and abs(a[k] - a[i]) <= budget and k < r){
budget -= abs(a[k] - a[i]);
++how_many;
++k;
}
else
break;
}
j = ((r + 1)/2) - 1, k = ((r + 1)/2) + 1, i = (r + 1) / 2;
budget = b;
long long int how_many1 = 1;
while(budget >= 0){
if(j < 0 and k >= r) break;
if(abs(a[j] - a[i]) <= abs(a[k] - a[i]) and abs(a[j] - a[i]) <= budget and j >= 0){
budget -= abs(a[j] - a[i]);
++how_many1;
--j;
}
else if(abs(a[k] - a[i]) <= abs(a[j] - a[i]) and abs(a[k] - a[i]) <= budget and k < r){
budget -= abs(a[k] - a[i]);
++how_many1;
++k;
}
else
break;
}
j = ((r - 1)/2) - 1, k = ((r - 1)/2) + 1, i = (r - 1) / 2;
budget = b;
long long int how_many2 = 1;
while(budget >= 0){
if(j < 0 and k >= r) break;
if(abs(a[j] - a[i]) <= abs(a[k] - a[i]) and abs(a[j] - a[i]) <= budget and j >= 0){
budget -= abs(a[j] - a[i]);
++how_many2;
--j;
}
else if(abs(a[k] - a[i]) <= abs(a[j] - a[i]) and abs(a[k] - a[i]) <= budget and k < r){
budget -= abs(a[k] - a[i]);
++how_many2;
++k;
}
else
break;
}
return max({how_many1, how_many, how_many2});
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
364 KB |
Output is correct |
3 |
Correct |
17 ms |
748 KB |
Output is correct |
4 |
Correct |
19 ms |
876 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
9 ms |
492 KB |
Output is correct |
7 |
Correct |
15 ms |
748 KB |
Output is correct |
8 |
Correct |
15 ms |
768 KB |
Output is correct |
9 |
Correct |
7 ms |
492 KB |
Output is correct |
10 |
Correct |
10 ms |
492 KB |
Output is correct |
11 |
Incorrect |
17 ms |
748 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |