#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } ll ans = 0; ll sum = 0; priority_queue , greater> pque; for (int i = N - 1; i >= 1; --i) { ll a = A[i]; pque.push(a); sum += a; if (i % 2 == 1) { ans = max(ans, sum); } if (pque.size() >= K) { ll v = pque.top(); sum -= v; pque.pop(); } } cout << ans << endl; return 0; }