/* -*- coding: utf-8 -*- * * 77.cc: No.77 レンガのピラミッド - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; const int INF = 1 << 30; /* typedef */ /* global variables */ int as[MAX_N * 2]; /* subroutines */ /* main */ int main() { int n; cin >> n; int asum = 0; for (int i = 0; i < n; i++) { cin >> as[i]; asum += as[i]; } int minsum = INF; for (int k = 1;; k += 2) { int hk = (k + 1) / 2; if (hk * hk > asum) break; int maxi = max(n, k); for (int i = 0; i + k <= maxi; i++) { int sum = 0; for (int j = 0; j < n; j++) { int j0 = j - i; int paj = (j0 < 0 || j0 >= k) ? 0 : (j0 >= hk) ? k - j0 : j0 + 1; //printf("%d,%d: %d\n", k, i, pai); if (as[j] > paj) sum += as[j] - paj; } if (minsum > sum) minsum = sum; } } printf("%d\n", minsum); return 0; }