#include using namespace std; typedef long long ll; typedef pair PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i].first; a[i].second = i; } a[1] = {0, 1}; sort(a.begin() + 1, a.end(), [&](PII a, PII b){ if (a.first != b.first) return a.first > b.first; return a.second < b.second; }); ll sum = 0; set s; for (int i = 1; i <= k; i++) { sum += a[i].first; s.insert(a[i].second); } if (*s.begin() % 2 == 0) { cout << sum << '\n'; } else { auto it = next(s.begin()); int x = n + 1; if (it != s.end()) { x = *it; } int mx = 0; for (int i = 1; i <= n; i++) { if (a[i].second % 2 == 0 and a[i].second < x) { mx = max(mx, a[i].first); } if (a[i].second == *s.begin()) { sum -= a[i].first; } } sum += mx; cout << sum << '\n'; } return 0; }