#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[] , long long B){
int best = 0;
vector<long long> v(R);
for(int i = 0 ; i < R ; i++){
v[i] = (long long) X[i];
}
vector<long long> pref(R);
for(int i = 0 ; i < R ; i++){
if(i == 0) pref[i] = X[i];
else pref[i] = X[i] + pref[i - 1];
}
for(int i = 1 ; i < R ; i++){
int ans_left = 0 , ans_right = 0;
long long s_left = 0 , s_right = 0;
int l = i - 1 , r = i + 1;
while(l >= 0 || r < R){
long long f_dist = (l >= 0 ? X[i] - X[l] : (long long)1e18) , s_dist = (r < R ? X[r] - X[i] : (long long)1e18);
if(f_dist >= s_dist){
int id = upper_bound(v.begin(),v.end() , v[i] + f_dist) - v.begin();
long long sum = pref[id - 1] - pref[i];
long long q = sum - (id - i - 1) * X[i];
s_right = max(s_right , q);
if(s_right + s_left <= B) {
ans_right = (id - i - 1);
r = id;
}
}
else{
int id = lower_bound(v.begin(),v.end() , v[i] - s_dist) - v.begin();
long long sum = pref[i - 1] - (id > 0 ? pref[id - 1] : 0);
long long q = (i - id) * X[i] - sum;
s_left = max(s_left , q);
if(s_left + s_right <= B) {
ans_left = (i - id);
l = id - 1;
}
}
if(s_left + s_right > B) break;
}
long long s = s_left + s_right;
int ans = ans_left + ans_right;
while(l >= 0 || r < R){
if((l < 0) || (r < R && X[r] - X[i] <= X[i] - X[l])){
s += X[r] - X[i];
r++;
}
else if((r >= R) || (l >= 0 && X[i] - X[l] <= X[r] - X[i])){
s += X[i] - X[l];
l--;
}
if(s > B) break;
ans++;
}
best = max(best , ans);
if(best == R - 1) break;
}
return best + 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
244 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
9 ms |
204 KB |
Output is correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
588 KB |
Output is correct |
2 |
Correct |
40 ms |
704 KB |
Output is correct |
3 |
Correct |
12 ms |
2184 KB |
Output is correct |
4 |
Execution timed out |
1090 ms |
2252 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |