# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115581 | vjudge1 | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int R;
ll L, B;
vector<ll> X;
vector<ll> prefixSum;
bool check(int K) {
int N = R;
for (int i = 0; i <= N - K; ++i) {
int j = i + K - 1;
int m = (i + j) / 2;
int leftCount = m - i;
ll sumLeft = (leftCount > 0 ? prefixSum[m - 1] - (i > 0 ? prefixSum[i - 1] : 0) : 0);
int rightCount = j - m;
ll sumRight = (rightCount > 0 ? prefixSum[j] - prefixSum[m] : 0);
ll totalCost = X[m] * (ll)leftCount - sumLeft + sumRight - X[m] * (ll)rightCount;
if (totalCost <= B) {
return true;
}
}
return false;
}
int main() {
cin >> R >> L >> B;
X.resize(R);
for (int i = 0; i < R; ++i) {
cin >> X[i];
}
prefixSum.resize(R);
prefixSum[0] = X[0];
for (int i = 1; i < R; ++i) {
prefixSum[i] = prefixSum[i - 1] + X[i];
}
int low = 1, high = R;
int ans = 0;
while (low <= high) {
int mid = (low + high) / 2;
if (check(mid)) {
ans = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
cout << ans << endl;
return 0;
}