# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27151 | 2017-07-09T16:17:06 Z | dwik | Rice Hub (IOI11_ricehub) | C++11 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; int sum[100009]; int cost(int a,int b){ int ret = 0; int mid = (a+b)/2; ret += sum[b]-sum[mid]-(sum[mid]-sum[mid-1])*(b-mid); ret += (sum[mid]-sum[mid-1])*(mid-a) - (sum[mid]-sum[a-1]); return ret; } int besthub(int n,int l,int x[],int b){ sum[1] = x[0]; for(int i=2;i<=n;i++){ sum[i] += sum[i-2]+x[i-1]; } int j = 1; int id = -1; int ans = 0; for(int i=1;i<=n;i++){ while(j<=n && cost(i,j)<=b){ j++; } if(cost(i,j-1)<=b){ if(j-i > ans){ ans = j-i; } } i++; j = max(j,i); } return ans; } /*int main(){ int n,l,x[100009],b; cin>>n>>l>>b; for(int i=0;i<n;i++)cin>>x[i]; cout<<besthub(n,l,x,b)<<endl; }*/ /* 5 20 6 1 2 10 12 14 */