# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110407 | 2019-05-10T19:24:37 Z | ioilolcom | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; #define endl "\n" #define x first #define y second #define pii pair<int,int> typedef long long int ll; vector<int> v; int besthub(int R, int L, int X[], long long B) { int n=r; ll w=b; v.resize(n+1); for(int i=0; i<n; i++) { v[i+1]=X[i]; } int idx=n/2 +(n%2); vector<pii> l,r; int cur=0; int curv=0; for(int i=idx+1; i<=n; i++) { curv+=v[i]-v[idx]; cur++; r.push_back({curv,cur}); } r.push_back({0,0}); l.push_back({0,0}); cur=0; curv=0; for(int i=idx-1; i>=0; i--) { curv+=abs(v[i]-v[idx]); cur++; l.push_back({curv,cur}); } int ans=0; for(auto u:l) { for(auto v:r) { if(u.x+v.x<=w) { ans=max(ans,u.y+v.y); } } } ans++; return ans; }