이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
int a[MAXN], n;
int ok(ll b, int len) {
ll cur = 0;
for (int i = 0; i < len; i++)
cur += abs((ll) a[i] - a[(len - 1) / 2]);
if (cur <= b)
return 1;
for (int i = len; i < n; i++) {
cur += (ll) (a[(len-1)/2+i-len+1]-a[(len-1)/2+i-len]) * (ll) ((len-1)/2+1);
cur -= (ll) (a[(len-1)/2+i-len+1]-a[(len-1)/2+i-len]) * (ll) (len-((len-1)/2+1));
cur -= abs((ll) a[i - len] - a[(len-1)/2+i-len+1]);
cur += abs((ll) a[i] - a[(len-1)/2+i-len+1]);
if (cur <= b)
return 1;
}
return 0;
}
int besthub(int r, int l, int x[], ll b) {
for (int i = 0; i < r; i++)
a[i] = x[i];
n = r;
int lo = 1, hi = r, ans = 1;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (ok(b, m))
lo = m + 1, ans = m;
else
hi = m - 1;
}
return ans;
}
/*int main()
{
int ans = besthub(5, 20, {1, 2, 10, 12, 14}, 6);
pri(ans);
return 0;
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |