#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; 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> pq; for(int i = n - 1; i >= 0; i--) { if(i % 2 == 1) { ans = max(ans, sum + a[i]); } sum += a[i]; pq.push(a[i]); if(pq.size() >= k) { sum -= pq.top(); pq.pop(); } } cout << ans << endl; return 0; }