# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
634650 | 2022-08-24T16:24:29 Z | rockoana | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include <vector> #include "ricehub.h" using namespace std; vector<long long> s; long long cost(int st, int dr, int X[]) { int mid = (st + dr) / 2; // X[mid + 1] - X[mid] + X[mid + 2] - X[mid]...X[dr] - X[mid]; // X[mid] - X[mid] + X[mid] - X[mid - 1] + ... + X[mid] - X[st] long long res = s[dr] - s[mid] - s[mid]; if (st != 0) { res += s[st - 1]; } if ((dr - st + 1) % 2 == 1) { res += X[mid]; } return res; } int besthub(int R, int L, int X[], long long B) { s.assign(R, 0); for (i64 i = 0; i < R; i++) { s[i] += X[i]; if (i != 0) { s[i] += s[i - 1]; } } int st = 0; int res = 0; for (int i = 0; i < R; i++) { while (cost(st, i, X) > B) { st++; } res = max(res, i - st + 1); } return res; }