#include using namespace std; long long n, k, m; long long a[200000], d[200000]; priority_queue, greater> Q; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = n - 1; i > 0; i--) { d[i - 1] = d[i]; if (Q.size() < k - 1) { Q.push(a[i]); d[i - 1] += a[i]; } else { long long t = Q.top(); if (t < a[i]) { Q.pop(); Q.push(a[i]); d[i - 1] += a[i] - t; } } } for (int i = 1; i < n; i += 2) m = max(m, a[i] + d[i]); cout << m << endl; }