#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
#define endl '\n';
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int r;
vector<ll> x;
vector<ll> pre;
ll l;
ll b;
bool test(int k) {
FOR(i,0,r-k+1) {
int mid = (i + i + k - 1)/2;
ll lft = mid - i + 1;
ll rgt = (i + k - 1) - mid;
// cout << lft << " " << rgt << endl;
ll tot = lft * x[mid] - (pre[mid+1] - pre[i]) + (pre[i + k] - pre[mid + 1]) - rgt * x[mid];
// cout << i << " " << i + k - 1 << ": " << tot << endl;
if(tot <= b) {
return true;
}
}
return false;
}
int besthub(int R, int L, int X[], ll B) {
r = R;
FOR(i,0,r) x.pb(X[i]);
l = L;
b = B;
pre.resize(r+1);
FOR(i,1,r+1) {
pre[i] = x[i-1] + pre[i-1];
}
int lo = 1;
int hi = r;
while(lo != hi) {
int mid = (lo + hi + 1)/2;
bool good = test(mid);
if(good) {
lo = mid;
} else {
hi = mid-1;
}
}
return lo;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
292 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 |
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 |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
312 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
444 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 |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
724 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
13 ms |
3400 KB |
Output is correct |
4 |
Correct |
13 ms |
3384 KB |
Output is correct |
5 |
Correct |
6 ms |
1724 KB |
Output is correct |
6 |
Correct |
6 ms |
1740 KB |
Output is correct |
7 |
Correct |
10 ms |
3144 KB |
Output is correct |
8 |
Correct |
11 ms |
3180 KB |
Output is correct |
9 |
Correct |
6 ms |
1688 KB |
Output is correct |
10 |
Correct |
8 ms |
1612 KB |
Output is correct |
11 |
Correct |
12 ms |
3392 KB |
Output is correct |
12 |
Correct |
12 ms |
3392 KB |
Output is correct |
13 |
Correct |
7 ms |
1744 KB |
Output is correct |
14 |
Correct |
6 ms |
1740 KB |
Output is correct |
15 |
Correct |
9 ms |
2596 KB |
Output is correct |
16 |
Correct |
10 ms |
2632 KB |
Output is correct |
17 |
Correct |
12 ms |
3176 KB |
Output is correct |
18 |
Correct |
11 ms |
3072 KB |
Output is correct |
19 |
Correct |
13 ms |
3208 KB |
Output is correct |
20 |
Correct |
12 ms |
3272 KB |
Output is correct |