#include #include using namespace std; using namespace atcoder; using mint = modint998244353; using ll = long long; #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int n, k; cin >> n >> k; vector a(n); rep(i, n) cin >> a[i]; ll summ = 0; ll ans = 0; priority_queue, greater> q; for (int i = n - 1; i >= 0; i--){ if(i % 2){ ans = max(ans, summ + a[i]); } q.push(a[i]); summ += a[i]; if(q.size() >= k){ summ -= q.top(); q.pop(); } } cout << ans << endl; return 0; }