/* -*- coding: utf-8 -*- * * 1808.cc: No.1808 Fullgold Alchemist - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N]; /* subroutines */ bool check(int n, int x) { ll sum = 0; for (int i = 0; i < n; i++) { if (x > as[i] + sum) return false; sum += as[i] - x; } return true; } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); int maxa = *max_element(as, as + n); int x0 = 0, x1 = maxa + 1; while (x0 + 1 < x1) { int x = (x0 + x1) / 2; if (check(n, x)) x0 = x; else x1 = x; } printf("%d\n", x0 / m); return 0; }