이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "ricehub.h"
#include <iostream>
#include <vector>
#define int long long
using namespace std;
int32_t besthub(int32_t R, int32_t L, int32_t X[], long long B)
{
int n = R;
vector<int> dpSum(n + 1);
for (int i = 1; i <= n; i++) {
dpSum[i] = dpSum[i - 1] + X[i - 1];
}
auto rangeSum = [=](int a, int b) -> int {
return dpSum[b + 1] - dpSum[a];
};
auto cost = [=](int from, int to) -> int {
int median = (from + to) / 2;
int leftN = median - from;
int leftSum = rangeSum(from, median - 1);
int rightN = to - median;
int rightSum = rangeSum(median + 1, to);
int currCost = (X[median] * leftN - leftSum) + (rightSum - X[median] * rightN);
return currCost;
};
int from = 0;
int to = 0;
int res = 1;
while (true) {
to++;
if (to >= n) break;
int currCost = cost(from, to);
if (currCost > B) from++;
else res = max(res, to - from + 1);
}
return res;
}
# | 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... |