#include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template using vc = vector; template using vvc = vc>; using pi = pair; using vi = vc; using vvi = vvc; #define rep(i,a,b) for (int i = a; i < b; i++) #define irep(i,a,b) for (int i = a; i > b; i--) #define print(n) cout << n << endl #define rup(a,b) (a+b-1)/b int main(){ cout << fixed << setprecision(15); int N,K; cin >> N >> K; vc A(N,0); rep(i,0,N) cin >> A[i]; ll ans = 0; multiset d; ll aa = 0; int now = 0; irep(i,A.size()-1,0){ if (now <= K-1){ now++; ans += A[i]; d.insert(A[i]); continue; } if (i%2 == 1){ aa = max(ans+A[i],aa); } d.insert(A[i]); ll b = *d.begin(); ans += A[i] - b; d.erase(d.begin()); } print(ans); //system("pause"); return 0; }