#include "ricehub.h"
/* Im the best and i work like that */
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define Mp make_pair
#define point complex
#define endl '\n'
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file_io freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define mashtali return cout << "Hello, World!", 0;
const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
const double pi = acos(-1);
const ld eps = 1e-18;
const ld one = 1.;
ll pw(ll a, ll b, ll M, ll ret = 1) { if(a == 0) return 0; a %= M; while(b) { ret = (b & 1? ret * a % M : ret), a = a * a % M, b >>= 1; } return ret % M; }
mt19937 rng(time(nullptr));
int n;
ll ps[N];
inline ll get(int l, int r)
{
return ps[r] - (l <= 0? 0 : ps[l - 1]);
}
int besthub(int _n, int L, int X[], ll B)
{
n = _n;
for(int i = 0; i < n; i ++)
{
ps[i] += X[i];
ps[i + 1] += ps[i];
}
int ans = 0;
for(int i = 0; i < n; i ++)
{
int d = 0, up = min(i, n - 1 - i) + 1;
while(up - d > 1)
{
int mid = (up + d) >> 1;
ll cu = -get(i - mid, i) + get(i, i + mid);
if(cu <= B)
{
d = mid;
ans = max(ans, d << 1 | 1);
if(i + mid + 1 < n && cu + X[i + mid + 1] - X[i] <= B)
{
ans = max(ans, d * 2 + 2);
}
}
else up = mid;
}
}
return ans;
}
/* check corner case(n = 1?), watch for negetive index or overflow */
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
244 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 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 |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
468 KB |
Output is correct |
3 |
Correct |
16 ms |
1448 KB |
Output is correct |
4 |
Correct |
17 ms |
1384 KB |
Output is correct |
5 |
Correct |
7 ms |
852 KB |
Output is correct |
6 |
Correct |
6 ms |
852 KB |
Output is correct |
7 |
Correct |
13 ms |
1492 KB |
Output is correct |
8 |
Correct |
14 ms |
1492 KB |
Output is correct |
9 |
Correct |
9 ms |
908 KB |
Output is correct |
10 |
Correct |
11 ms |
852 KB |
Output is correct |
11 |
Correct |
15 ms |
1492 KB |
Output is correct |
12 |
Correct |
21 ms |
1428 KB |
Output is correct |
13 |
Correct |
8 ms |
884 KB |
Output is correct |
14 |
Correct |
10 ms |
844 KB |
Output is correct |
15 |
Correct |
12 ms |
1096 KB |
Output is correct |
16 |
Correct |
16 ms |
1188 KB |
Output is correct |
17 |
Correct |
14 ms |
1364 KB |
Output is correct |
18 |
Correct |
14 ms |
1264 KB |
Output is correct |
19 |
Correct |
15 ms |
1428 KB |
Output is correct |
20 |
Correct |
17 ms |
1308 KB |
Output is correct |