# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1252658 | pvb.tunglam | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define hash _hash_
#define y1 _y1_
#define left _left_
#define right _right_
#define dec _dec_
#define int long long
using namespace std;
/*------------- I alone decide my fate! --------------*/
/* In the hush of the fields, the hub shall arise… */
int besthub(int R, int /*L*/, const vector<int>& X, long long B) {
static long long pref[100005]; // tiền tố S
for (int i = 0; i < R; ++i)
pref[i] = (i ? pref[i-1] : 0) + X[i];
auto sum = [&](int l, int r) -> long long { // Σ X[l..r]
return pref[r] - (l ? pref[l-1] : 0);
};
int ans = 0;
int l = 0;
for (int r = 0; r < R; ++r) {
while (l <= r) {
int m = (l + r) >> 1;
long long leftCnt = m - l;
long long rightCnt = r - m;
long long cost =
leftCnt * X[m] - sum(l, m - 1)
+ sum(m + 1, r) - rightCnt * X[m];
if (cost <= B) break;
++l;
}
ans = max(ans, r - l + 1);
}
return ans;
}
/*---------------------------*/
#ifdef LOCAL
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int R, L; long long B;
if (!(cin >> R >> L >> B)) return 0;
vector<int> X(R);
for (int &x : X) cin >> x;
cout << besthub(R, L, X, B) << '\n';
}
#endif
/*
…Across the silent paddies, carts will roll,
For we have placed the hub where numbers told.
*/