#include <bits/stdc++.h>
// #include <grader.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define scld(t) scanf("%ld", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long int li;
typedef unsigned long int uli;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
int besthub(int r, int l, int X[], lli b)
{
int lo = 0;
int hi = r;
vll vec(r);
frange(i, r) vec[i] = X[i];
vll pref(r);
pref[0] = vec[0];
forr(i, 1, r) pref[i] = pref[i - 1] + vec[i];
while (lo != hi)
{
int mid = (hi + lo + 1) / 2;
bool check = false;
forr(i, 0, r)
{
if (i - mid / 2 >= 0 && i + (mid - 1) / 2 < r)
{
int i1 = mid / 2;
int i2 = (mid - 1) / 2;
lli v = pref[i];
if (i - i1 > 0)
v -= pref[i - i1 - 1];
v = -v;
v += vec[i] * (i1 + 1);
v += pref[i + i2] - pref[i];
v -= vec[i] * i2;
if (v <= b)
{
check = true;
break;
}
}
if (i - (mid - 1) / 2 >= 0 && i + (mid) / 2 < r)
{
int i1 = (mid - 1) / 2;
int i2 = (mid) / 2;
lli v = pref[i];
if (i - i1 > 0)
v -= pref[i - i1 - 1];
v = -v;
v += vec[i] * (i1 + 1);
v += pref[i + i2] - pref[i];
v -= vec[i] * i2;
if (v <= b)
{
check = true;
break;
}
}
}
if (check)
{
lo = mid;
}
else
hi = mid - 1;
}
return lo;
}
// int main()
// {
// int r;
// lli l, b;
// scd(r);
// sclld(l);
// sclld(b);
// int vec[r];
// frange(i, r) scd(vec[i]);
// printf("%d", besthub(r, l, vec, b));
// }
# |
Verdict |
Execution time |
Memory |
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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
260 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
308 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 |
312 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
308 KB |
Output is correct |
25 |
Correct |
1 ms |
308 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 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 |
228 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 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 |
320 KB |
Output is correct |
28 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
808 KB |
Output is correct |
3 |
Correct |
13 ms |
3280 KB |
Output is correct |
4 |
Correct |
11 ms |
3284 KB |
Output is correct |
5 |
Correct |
6 ms |
1552 KB |
Output is correct |
6 |
Correct |
6 ms |
1608 KB |
Output is correct |
7 |
Correct |
9 ms |
3036 KB |
Output is correct |
8 |
Correct |
13 ms |
3028 KB |
Output is correct |
9 |
Correct |
7 ms |
1580 KB |
Output is correct |
10 |
Correct |
6 ms |
1504 KB |
Output is correct |
11 |
Correct |
12 ms |
3328 KB |
Output is correct |
12 |
Correct |
11 ms |
3296 KB |
Output is correct |
13 |
Correct |
8 ms |
1620 KB |
Output is correct |
14 |
Correct |
7 ms |
1608 KB |
Output is correct |
15 |
Correct |
10 ms |
2480 KB |
Output is correct |
16 |
Correct |
8 ms |
2524 KB |
Output is correct |
17 |
Correct |
12 ms |
2936 KB |
Output is correct |
18 |
Correct |
12 ms |
2884 KB |
Output is correct |
19 |
Correct |
11 ms |
3072 KB |
Output is correct |
20 |
Correct |
13 ms |
3072 KB |
Output is correct |