#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll r, l, x, b, fields[100000];
vector<ll> pref;
ll check(ll R, ll L, ll *fields, ll B) {
ll lo = L, hi = R;
while (lo < hi){
ll mid = (lo + hi + 1)/2;
ll k = (L + mid)/2;
ll cost = fields[k - 1]*(k - L + 1) - (pref[k] - pref[L - 1]) +(pref[mid] - pref[k]) - (mid - k)*fields[k-1];
if (cost > B) {
hi = mid - 1;
} else {
lo = mid;
}
}
return lo - L + 1;
}
ll besthub(ll R, ll L, ll fields[], ll B) {
pref.resize(R + 1);
for(int i = 0; i < R; i++){
pref[i+1] += pref[i];
pref[i+1] += fields[i];
}
ll ans = INT_MIN;
for (int i = 1; i <= R; i++) {
ans = max(ans, check(R, i, fields, B));
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin >> r >> l >> b;
for (int i = 0; i < r; i++) {
cin >> fields[i];
}
cout << besthub(r, l, fields, b) << "\n";
}
Compilation message
/usr/bin/ld: /tmp/ccSNFlZx.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccXBZOyz.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccSNFlZx.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status