#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nax = 1e5 + 5;
int n, maxi, a[nax], pref[nax], suff[nax];
ll b;
// Subtask 4
bool chk(int x) {
if (x > n || x < 1) return false;
for (int i = 1; i <= n - x + 1; ++i) {
int l = i, r = i + x - 1;
int median = (l + r) / 2;
// l..(median - 1)
int num_left = max(0, (median - 1 - l) + 1);
int num_right = max(0, r - (median + 1) + 1);
int cost_left = a[median] * num_left - (pref[median - 1] - pref[l - 1]);
int cost_right = suff[median + 1] - suff[r + 1] - a[median * num_right];
if (cost_left + cost_right <= b) return true;
// (median + 1)..r
}
return false;
}
int solve() {
for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
for (int i = n; i >= 1; --i) suff[i] = suff[i + 1] + a[i];
int l = 1, r = n;
while (r >= l) {
int mid = (l + r) / 2;
bool status = chk(mid);
if (status) {
if (chk(mid + 1)) l = mid + 1;
else {
return mid;
}
}
else {
r = mid - 1;
}
}
return 0;
}
int besthub(int R, int L, int X[], long long B) {
n = R;
maxi = L;
for (int i = 0; i < R; ++i) a[i + 1] = X[i];
b = B;
return solve();
}
Compilation message
ricehub.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization("unroll-loops, no-stack-protector")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
288 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1280 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |