# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335883 | sumit_kk10 | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
long long int besthub(int n, int l, int a[], long long int b){
long long int pre_sum[n] = {0}, suf_sum[n] = {0}, ans = 1;
pre_sum[0] = a[0];
suf_sum[n - 1] = a[n - 1];
for(int i = 1; i < n; ++i)
pre_sum[i] = pre_sum[i - 1] + a[i];
for(int i = n - 2; i >= 0; --i)
suf_sum[i] = suf_sum[i + 1] + a[i];
for(int left = 0; left < n; ++left){
int low = left, high = n - 1;
while(low <= high){
int right = (low + high) / 2;
long long int middle = (left + right) / 2;
long long int val = pre_sum[right] - pre_sum[middle] + suf_sum[left] - suf_sum[middle];
val -= (a[middle] * (right - left));
// cout << left << ' ' << right << ' ' << middle << ' ' << val << '\n';
if(val <= b){
ans = max(ans, (long long int) right - left + 1);
low = right + 1;
}
else
high = right - 1;
}
}
return ans;
}
int main(){
int n, l;
long long int b;
cin >> n >> l >> b;
int a[n];
for(int i = 0; i < n; ++i)
cin >> a[i];
cout << besthub(n, l, a, b) << '\n';
}