#include <bits/stdc++.h>
using namespace std;
typedef long long int;
#define f first
#define s second
int n, budget;
vector<int> psum;
vector<int> ssum;
bool check(int rice) {
int middle = (rice-1) / 2;
int right = middle+(rice)/2;
int minb = 1e9;
for (int i = 0; i <= n - rice; i++) {
int b = psum[i+right] - psum[i+middle] + ssum[i] - ssum[i+middle];
minb = min(b, minb);
}
//cout << "minb: " << minb << endl;
if (minb <= budget) return true;
return false;
}
int besthub(int r, ll maxcoor, int a[], int b) {
n = r;
budget = b;
int diff[n-1];
for (int i = 0; i < n-1; i++) {
diff[i] = a[i+1] - a[i];
}
psum.resize(n, 0);
ssum.resize(n, 0);
for (int i = 1; i < n; i++) {
psum[i] = a[i-1] + psum[i-1];
}
for (int i = n-2; i >= 0; i--) {
ssum[i] = a[i] + ssum[i+1];
}
int l = 1;
while (l < r) {
int mid = (l + r + 1) / 2;
//cout << "mid: " << mid << endl;
if (check(mid)) {
l = mid;
}
else {
r = mid - 1;
}
}
return l;
}
// signed main() {
// int r, l, b; cin >> r >> l >> b;
// int x[r];
// for (int i = 0; i < r; i++) cin >> x[i];
// besthub(r, l, x, b);
// }
Compilation message
ricehub.cpp:4:19: error: declaration does not declare anything [-fpermissive]
4 | typedef long long int;
| ^~~
ricehub.cpp:26:20: error: 'll' has not been declared
26 | int besthub(int r, ll maxcoor, int a[], int b) {
| ^~