#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; // using mint = modint1000000007; template using vec = vector; template using pa = pair; template using mipq = priority_queue, greater>; #define REP(_1, _2, _3, _4, name, ...) name #define REP1(i, n) for (auto i = decay_t{}; (i) < (n); ++(i)) #define REP2(i, l, r) for (auto i = (l); (i) < (r); ++(i)) #define REP3(i, l, r, d) for (auto i = (l); (i) < (r); i += (d)) #define rep(...) REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__) #define rrep(i, r, l) for (int i = (r); i >= (l); --i) template bool chmax(T &a, const T &b) { return (a < b ? a = b, true : false); } template bool chmin(T &a, const T &b) { return (a > b ? a = b, true : false); } constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 60; constexpr int mov[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int T = 1; // cin >> T; while (T--) solve(); } void solve() { int N, M; cin >> N >> M; mipq pq; rep(i, M) pq.push(0); ll ans = 0; rep(i, N) { int t; cin >> t; ll v = pq.top(); pq.pop(); chmax(ans, v + t); pq.push(v + t); } cout << ans << '\n'; }