/* * Author: nskybytskyi * Time: 2022-01-13 15:08:45 */ #include using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; vector a(n); for (auto& ai : a) { cin >> ai; } auto can = [&] (int mi) -> bool { int64_t balance = 0; for (auto ai : a) { ai += balance; if (ai < mi) { return false; } else { balance = ai - mi; } } return true; }; int lo = 0, hi = *max_element(a.begin(), a.end()) + 1; while (hi - lo > 1) { int mi = (lo + hi) >> 1; if (can(mi)) { lo = mi; } else { hi = mi; } } cout << lo << "\n"; return 0; }