# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284509 | 2020-08-27T14:20:29 Z | Basilhijaz | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include "ricehub.h" using namespace std; typedef long long ll; int besthub(int R, int L, ll X[], long long B) { ll pre[R + 1]; pre[0] = 0; for(int i = 0; i < R; i++){ pre[i + 1] = X[i] + pre[i]; } int lo = 0; int hi = R; while(lo < hi){ ll mid = (lo + hi + 1)/2; bool can = 0; for(int i = 0; i + mid - 1 < R; i++){ ll sum = 0; ll nos = (i + i + mid - 1)/2; sum += X[nos]*mid - (pre[nos] - pre[i]); sum += (pre[i + i + mid - 1] - pre[nos]) - X[nos]*mid; if(sum <= B){ can = 1; break; } } if(can){ lo = mid; } else{ hi = mid - 1; } } return lo; }