# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
584660 | 2022-06-27T18:42:14 Z | sofijavelkovska | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; long long besthub(long long n, long long p, long long a[], long long k) { long long prefix[n]; for (long long i=0; i<n; i++) { if (i==0) prefix[i]=a[i]; else prefix[i]=prefix[i-1]+a[i]; } long long l=0, r=0, m; long long maxrice=0; while (r<n) { m=(r+l)/2; long long distanceright, distanceleft; distanceright=prefix[r]-prefix[m]; if (l!=0) distanceleft=prefix[m-1]-prefix[l-1]; else if (m!=0) distanceleft=prefix[m-1]; else distanceleft=0; long long budget=(a[m]*(m-l)-distanceleft)+(distanceright-a[m]*(r-m)); if (budget<=k) { maxrice=max(maxrice, r-l+1); r=r+1; } else { r=r+1; l=l+1; } } return maxrice; } int main() { long long n, p, k; cin >> n >> p >> k; long long a[n]; for (long long i=0; i<n; i++) cin >> a[i]; cout << besthub(n, p, a, k); return 0; }