#include "ricehub.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define N 400005
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n;
ll niz[N];
ll seg[4 * N][2];
ll suff[N];
ll pref[N];
void init(int node, int l, int r){
if(l == r){
seg[node][0] = pref[l];
seg[node][1] = suff[l];
return;
}
int mid = (l + r) / 2;
init(node * 2, l, mid);
init(node * 2 + 1, mid + 1, r);
ff(j,0,1)seg[node][j] = seg[node * 2][j] + seg[node * 2 + 1][j];
}
ll query(int node, int l, int r, int levo, int desno, int idx){
if(r < levo || l > desno)return 0;
if(l >= levo && r <= desno)return seg[node][idx];
int mid = (l + r) / 2;
return query(node * 2, l, mid, levo, desno, idx) + query(node * 2 + 1, mid + 1, r, levo, desno, idx);
}
int besthub(int R, int L, int X[], long long B)
{
n = R;
ff(i,1,n)niz[i] = X[i - 1];
sort(niz + 1, niz + 1 + n);
ff(i,1,n){
pref[i] = niz[i] - niz[1];
}
fb(i,n,1){
suff[i] = niz[n] - niz[i];
}
init(1,1,n);
int res = 1;
ff(i,1,n){
int l = 0;
int r = min(n - i, i - 1);
while(l < r){
ll mid = (l + r + 1) / 2;
ll prvi = query(1,1,n,i,i + mid,0) - (mid + 1) * pref[i];
ll drugi = query(1,1,n,i - mid,i,1) - (mid + 1) * suff[i];
if(prvi + drugi <= B){
l = mid;
}
else r = mid - 1;
}
res = max(res, 2*l + 1);
if(i + l >= n)continue;
ll prvi = query(1,1,n,i,i + l + 1,0) - (l + 2) * pref[i];
ll drugi = query(1,1,n,i - l,i,1) - (l + 1) * suff[i];
if(prvi + drugi <= B)res = max(res, 2*l + 2);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
18 ms |
768 KB |
Output is correct |
22 |
Correct |
18 ms |
768 KB |
Output is correct |
23 |
Correct |
19 ms |
768 KB |
Output is correct |
24 |
Correct |
18 ms |
768 KB |
Output is correct |
25 |
Correct |
18 ms |
768 KB |
Output is correct |
26 |
Correct |
18 ms |
768 KB |
Output is correct |
27 |
Correct |
18 ms |
800 KB |
Output is correct |
28 |
Correct |
19 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
1920 KB |
Output is correct |
2 |
Correct |
90 ms |
1920 KB |
Output is correct |
3 |
Correct |
644 ms |
7288 KB |
Output is correct |
4 |
Correct |
637 ms |
7160 KB |
Output is correct |
5 |
Correct |
265 ms |
4216 KB |
Output is correct |
6 |
Correct |
258 ms |
4096 KB |
Output is correct |
7 |
Correct |
652 ms |
8056 KB |
Output is correct |
8 |
Correct |
648 ms |
8056 KB |
Output is correct |
9 |
Correct |
285 ms |
4096 KB |
Output is correct |
10 |
Correct |
286 ms |
4096 KB |
Output is correct |
11 |
Correct |
636 ms |
8312 KB |
Output is correct |
12 |
Correct |
650 ms |
8312 KB |
Output is correct |
13 |
Correct |
262 ms |
4216 KB |
Output is correct |
14 |
Correct |
258 ms |
4216 KB |
Output is correct |
15 |
Correct |
451 ms |
7328 KB |
Output is correct |
16 |
Correct |
473 ms |
7324 KB |
Output is correct |
17 |
Correct |
585 ms |
7884 KB |
Output is correct |
18 |
Correct |
573 ms |
7800 KB |
Output is correct |
19 |
Correct |
590 ms |
8184 KB |
Output is correct |
20 |
Correct |
606 ms |
8184 KB |
Output is correct |