# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1272405 | btkhg | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, vector<int> &X, long long B) {
vector<long long> P(R + 1, 0);
for (int i = 0; i < R; i++) P[i + 1] = P[i] + (long long)X[i];
auto costWindow = [&](int i, int j) -> long long {
int m = (i + j) / 2;
long long xm = X[m];
long long left = xm * (m - i) - (P[m] - P[i]);
long long right = (P[j + 1] - P[m + 1]) - xm * (j - m);
return left + right;
};
int ans = 0;
for (int i = 0, j = 0; j < R; j++) {
while (i <= j && costWindow(i, j) > B) ++i;
if (i <= j) ans = max(ans, j - i + 1);
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int R, L;
long long B;
cin >> R >> L >> B;
vector<int> X(R);
for (int i = 0; i < R; i++) cin >> X[i];
cout << besthub(R, L, X, B) << "\n";
return 0;
}