#include #include #include #include #include #include using namespace std; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int givenBlocks = accumulate(a.begin(), a.end(), 0); int minMovement = numeric_limits::max(); for (int height = 1;; ++height) { int width = height * 2 - 1; int blocks = 0; int movement = 0; for (int x = 0; x < max(width, a.size()); ++x) { int y; if (x < height) { y = x + 1; } else if (x < width) { y = 2 * height - x - 1; } else { y = 0; } blocks += y; int current = ((size_t)x < a.size() ? a[x] : 0); if (y < current) { movement += current - y; } } if (givenBlocks < blocks) { break; } minMovement = min(minMovement, movement); } cout << minMovement << endl; return 0; }