//In the name of God
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
vector<ll> vec;
ll ps[maxn];
ll sp[maxn];
map<ll, ll> cnt;
int besthub(int n, int L, int X[], ll B){
vec.pb(0);
for(int i = 0; i < n; i++){
cnt[X[i]]++;
if(vec.back() != X[i]){
vec.pb(X[i]);
}
}
vec.pb(L + 1);
for(int i = 1; i < Sz(vec); i++){
ps[i] = ps[i - 1] + cnt[vec[i]];
sp[i] = sp[i - 1] + 1ll * cnt[vec[i]] * vec[i];
}
ll ans = 0;
for(int i = 1; i + 1 < Sz(vec); i++){
int l = 0, r = L + 10, mid;
while(r - l > 1){
mid = (l + r) >> 1;
int ir = lower_bound(all(vec), vec[i] + mid) - vec.begin();
int il = upper_bound(all(vec), vec[i] - mid) - vec.begin();
if((sp[ir - 1] - sp[i] - (ps[ir - 1] - ps[i]) * vec[i]) + ((ps[i] - ps[il - 1]) * vec[i] - (sp[i] - sp[il - 1])) <= B){
l = mid;
}
else r = mid;
}
int ir = lower_bound(all(vec), vec[i] + l) - vec.begin();
int il = upper_bound(all(vec), vec[i] - l) - vec.begin();
ll x = (B - ((sp[ir - 1] - sp[i] - (ps[ir - 1] - ps[i]) * vec[i]) + ((ps[i] - ps[il - 1]) * vec[i] - (sp[i] - sp[il - 1])))) / l;
ans = max(ans, ps[ir - 1] - ps[il - 1] + min(x, cnt[vec[i] - l] + cnt[vec[i] + l]));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
224 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
1108 KB |
Output is correct |
24 |
Correct |
6 ms |
860 KB |
Output is correct |
25 |
Correct |
8 ms |
1108 KB |
Output is correct |
26 |
Correct |
7 ms |
980 KB |
Output is correct |
27 |
Correct |
10 ms |
980 KB |
Output is correct |
28 |
Correct |
14 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2128 KB |
Output is correct |
2 |
Correct |
50 ms |
2128 KB |
Output is correct |
3 |
Correct |
212 ms |
21736 KB |
Output is correct |
4 |
Correct |
267 ms |
15540 KB |
Output is correct |
5 |
Correct |
8 ms |
596 KB |
Output is correct |
6 |
Correct |
11 ms |
596 KB |
Output is correct |
7 |
Correct |
22 ms |
1688 KB |
Output is correct |
8 |
Correct |
23 ms |
1392 KB |
Output is correct |
9 |
Correct |
23 ms |
1388 KB |
Output is correct |
10 |
Correct |
25 ms |
1416 KB |
Output is correct |
11 |
Correct |
210 ms |
21808 KB |
Output is correct |
12 |
Correct |
258 ms |
15468 KB |
Output is correct |
13 |
Correct |
150 ms |
7516 KB |
Output is correct |
14 |
Correct |
142 ms |
7492 KB |
Output is correct |
15 |
Correct |
157 ms |
16316 KB |
Output is correct |
16 |
Correct |
207 ms |
11600 KB |
Output is correct |
17 |
Correct |
184 ms |
19388 KB |
Output is correct |
18 |
Correct |
252 ms |
13868 KB |
Output is correct |
19 |
Correct |
216 ms |
20628 KB |
Output is correct |
20 |
Correct |
248 ms |
14768 KB |
Output is correct |