# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1252670 | pvb.tunglam | 쌀 창고 (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… */
const int MAXR = 100000 + 5;
int R, L, B;
int X[MAXR], pref[MAXR];
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin >> R >> L >> B;
for (int i = 0; i < R; ++i) {
cin >> X[i];
}
// Xây mảng tiền tố: pref[i] = X[0] + … + X[i]
pref[0] = X[0];
for (int i = 1; i < R; ++i) {
pref[i] = pref[i-1] + X[i];
}
int ans = 0;
int l = 0;
// Duyệt r từ 0…R-1, đẩy l sao cho đoạn [l…r] luôn có cost ≤ B
for (int r = 0; r < R; ++r) {
while (l <= r) {
int m = (l + r) >> 1;
int leftCnt = m - l;
int rightCnt = r - m;
int sumLeft = (m-1 >= l) ? (pref[m-1] - (l ? pref[l-1] : 0)) : 0;
int sumRight = (r >= m+1) ? (pref[r] - pref[m]) : 0;
int cost = leftCnt * X[m] - sumLeft
+ sumRight - rightCnt * X[m];
if (cost <= B) break;
++l;
}
ans = max(ans, r - l + 1);
}
cout << ans << "\n";
return 0;
}
/*
…Across the silent paddies, carts will roll,
For we have placed the hub where numbers told.
*/