이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub (int r, int l, int *x, long long b) {
vector<long long> psa(r);
auto get = [&] (int pos) {
return pos < 0 ? 0LL : psa[pos];
};
for (int i = 0; i < r; i++) psa[i] = get(i-1) + x[i];
int ret = 0;
for (int i = 0; i < r; i++) { //i^{th} is the median
int low = 1, high = min(r,min(i+1,r-i) * 2), mid, ans = 0;
while (low <= high) {
mid = (low + high) / 2;
int take = (mid - 1) / 2;
long long go = get(i - take - 1) + get(i + take) - get(i) - get(i-1);
if (!(mid & 1)) go += min(i>=take+1?x[i]-x[i-take-1]:INT_MAX,i+take+1<r?x[i+take+1]-x[i]:INT_MAX);
if (go <= b) low = (ans = mid) + 1;
else high = mid - 1;
}
ret = max(ret,ans);
}
return ret;
}
# | 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... |