#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int n, l;
const int dydis = 1e5 + 10;
long long pref[dydis];
long long sm(int l, int r){
return pref[r] - (l == 0 ? 0ll : pref[l-1]);
}
pair<long long, long long> f(int dst, int ind, int mas[]){
int l = 0; int r = ind-1; int mid;
int L = ind; int R = ind;
while(l <= r){
mid = (l + r) / 2;
if(abs(mas[mid]-mas[ind]) <= dst){
L = min(L, mid);
r = mid-1;
}else{
l = mid+1;
}
}
l = ind+1; r = n-1;
while(l <= r){
mid = (l + r) / 2;
if(abs(mas[mid] - mas[ind]) <= dst){
R = max(R, mid);
l = mid+1;
}else{
r = mid-1;
}
}
long long SL = 1ll * (ind - L + 1) * mas[ind] - sm(L, ind);
long long SR = sm(ind, R) - 1ll * (R - ind + 1) * mas[ind];
// cout << "SR = " << sm(ind, R) << " - " << 1ll * (R - ind + 1) * mas[ind] << ", MAS[" << ind << "] = " << mas[ind] << " ";
// cout << "dst = " << dst << ", o i = " << ind << ", tai L = " << L << ", R = " << R << ", tai ret = " << SL << " + " << SR << endl;
return make_pair(SL + SR, R - L + 1);
}
int besthub(int N, int L, int X[], long long B) {
n = N; l = L;
for(int i = 0; i < n; i++) pref[i] = 1ll * X[i] + (i == 0 ? 0ll : pref[i-1]);
long long ans = 0;
for(int i = 0; i < n; i++){
long long st = 1;
int l = 0, r = 1e9, mid;
while(l <= r){
mid = (l + r) / 2;
auto ff = f(mid, i, X);
if(ff.first <= B){
st = max(st, ff.second);
l = mid+1;
}else{
r = mid-1;
}
}
// cout << "i = " << i << ", st = " << st << endl;
ans = max(ans, st);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
660 KB |
Output is correct |
2 |
Correct |
47 ms |
664 KB |
Output is correct |
3 |
Correct |
251 ms |
2508 KB |
Output is correct |
4 |
Correct |
315 ms |
2524 KB |
Output is correct |
5 |
Incorrect |
167 ms |
1228 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |