#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,K; cin>>N>>K; vector<ll>A(N); for(int i=0;i<N;i++)cin>>A[i]; priority_queue<ll,vector<ll>,greater<ll>>pq; ll sum=0,ans=0; for(int i=N-1;i>=0;i--){ if(pq.size()<K-1){ pq.push(A[i]); sum+=A[i]; } else{ if(i%2==1)ans=max(ans,A[i]+sum); if(pq.top()<A[i]){ sum-=pq.top(); pq.pop(); sum+=A[i]; pq.push(A[i]); } } } cout<<ans<<"\n"; }