#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 100005
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;
int 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];
}
int 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){
int 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 |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
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 |
1 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 |
388 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 |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 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 |
1 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 |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 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 |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 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 |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 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 |
18 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 |
17 ms |
768 KB |
Output is correct |
27 |
Correct |
19 ms |
888 KB |
Output is correct |
28 |
Correct |
19 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
1920 KB |
Output is correct |
2 |
Correct |
86 ms |
1920 KB |
Output is correct |
3 |
Correct |
627 ms |
7896 KB |
Output is correct |
4 |
Incorrect |
627 ms |
7928 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |