이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "ricehub.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int besthub(int R, int L, int X[], long long B)
{
ll pref[R];
ll Big[R];
pref[0] = 0;
for(int i = 0; i < R; i++)
{
if(i > 0)
pref[i] = pref[i - 1];
pref[i] += X[i];
Big[i] = X[i];
}
int left = 1, right = R;
int ans = 0;
while(left <= right)
{
int m = (left + right) / 2; // We are controlling whether we can get m rices. We use binary search because rice count is monotonic. For example, we can get 6 rices, if we can get 7 rices.
//int mid = 1;
bool valid = false;
for(int i = 0; i + m - 1 < R; i++)
{
ll mid = i + (m-1) / 2;
ll price = Big[mid] * (mid - i + 1) - (pref[mid] - pref[i - 1]);
price += (pref[i + m - 1] - pref[mid]) - Big[mid] * (i + m - 1 - mid);
if(price <= B)
valid = true;
}
if(valid) {
left = m + 1;
ans = m;
}
else
right = m - 1;
}
return ans;
}
# | 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... |