#include "ricehub.h"
#pragma GCC optimize("O3")
#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){
if(l > r) return 0;
return pref[r] - (l == 0 ? 0ll : pref[l-1]);
}
unordered_map<int, int> kek;
pair<long long, long long> f(int dst, int ind, int mas[], long long B){
int l = 0; int r = ind; int mid;
int L = ind+1; int R = ind-1;
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; 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];
long long lieka = B - SL - SR;
int pl = 0;
if(lieka > 0){
int galiu = lieka / dst;
galiu = min(galiu, kek[mas[ind] + dst] + kek[mas[ind] - dst]);
pl = galiu;
}
// 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, max(R - L + 1, 0)+pl);
}
int besthub(int N, int L, int X[], long long B) {
n = N; l = L;
for(int i = 0; i < n; i++) kek[X[i]]++;
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, B);
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;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 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 |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 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 |
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 |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
12 ms |
2444 KB |
Output is correct |
4 |
Correct |
5 ms |
1100 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
460 KB |
Output is correct |
13 |
Correct |
10 ms |
2264 KB |
Output is correct |
14 |
Correct |
4 ms |
716 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
8 ms |
2008 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
19 |
Correct |
11 ms |
2648 KB |
Output is correct |
20 |
Correct |
5 ms |
1100 KB |
Output is correct |
21 |
Correct |
14 ms |
396 KB |
Output is correct |
22 |
Correct |
14 ms |
376 KB |
Output is correct |
23 |
Correct |
42 ms |
7204 KB |
Output is correct |
24 |
Correct |
18 ms |
1228 KB |
Output is correct |
25 |
Correct |
55 ms |
7396 KB |
Output is correct |
26 |
Correct |
31 ms |
4344 KB |
Output is correct |
27 |
Correct |
29 ms |
4080 KB |
Output is correct |
28 |
Correct |
28 ms |
4008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
2896 KB |
Output is correct |
2 |
Correct |
60 ms |
2880 KB |
Output is correct |
3 |
Execution timed out |
1087 ms |
119396 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |