# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969901 | 2024-04-25T19:01:15 Z | urieg | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> // for moondance v3 using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll R, L, B; cin>>R>>L>>B; vector<ll>x(R), p(R); for(int i=0;i<R;i++){ cin>>x[i]; p[i] = x[i]; if(i)p[i] += p[i-1]; } int ans = 0; ll sum = 0; int l = 0, r = 0; for(int i =0;i<R;i++){ l = r = i; sum = 0; while(l>0 && r<R-1 && sum <= B){ if(l>0 && r<R-1){ if(x[i]-x[l-1] < x[r+1]-x[i]){ if(sum + x[i]-x[l-1] <= B){ sum += x[i]-x[l-1]; l--; } } else{ if(sum + x[r+1]-x[i] <= B){ sum += x[r+1]-x[i]; r++; } } } else if(l>0){ if(sum + x[i]-x[l-1] <= B){ sum += x[i]-x[l-1]; l--; } } else if(r<R-1){ if(sum + x[r+1]-x[i] <= B){ sum += x[r+1]-x[i]; r++; } } } ans = max(ans, r-l+1); } cout<<ans; return 0; }