#include // clang-format off using namespace std;constexpr int INF=1001001001;constexpr long long INFll=1001001001001001001;namespace viewer{using s=string;templates f(T i){s S=i==INF||i==INFll?"inf":to_string(i);return s(max(0,3-int(S.size())),' ')+S;} templateauto v(T&x,s&&e)->decltype(cerr<void v(const pair&p,s&&e="\n"){cerr<<"(";v(p.first,", ");v(p.second,")"+e);}templatevoid v(const tuple&t,s&&e="\n"){cerr<<"(";v(get<0>(t),", ");v(get<1>(t),")"+e);}templatevoid v(const tuple&t,s&&e="\n"){cerr<<"(";v(get<0>(t),", ");v(get<1>(t),", ");v(get<2>(t),")"+e);}templatevoid v(const tuple&t,s&&e="\n"){cerr<<"(";v(get<0>(t),", ");v(get<1>(t),", ");v(get<2>(t),", ");v(get<3>(t),")"+e);} templatevoid v(const vector&vx,s);templateauto ve(int,const vector&vx)->decltype(cerr<auto ve(bool,const vector&vx){cerr<<"{\n";for(const T&x:vx)cerr<<" ",v(x,",");cerr<<"}\n";}templatevoid v(const vector&vx,s){ve(0,vx);} templatevoid v(const deque&q,s&&e){v(vector(q.begin(),q.end()),e);}templatevoid v(const set&S,s&&e){v(vector(S.begin(),S.end()),e);}templatevoid v(const multiset&S,s&&e){v(vector(S.begin(),S.end()),e);}templatevoid v(const unordered_set&S,s&&e){v(vector(S.begin(),S.end()),e);} templatevoid v(const priority_queue&p,s&&e){priority_queueq=p;vectorz;while(!q.empty()){z.push_back(q.top());q.pop();}v(z,e);}templatevoid v(const map&m,s&&e){cerr<<"{"<<(m.empty()?"":"\n");for(const auto&kv:m){cerr<<" [";v(kv.first,"");cerr<<"] : ";v(kv.second,"");cerr<<"\n";}cerr<<"}"+e;} templatevoid _view(int n,s&S,T&var){cerr<<"\033[1;32m"<void grid(T _){}void grid(const vector>&vvb){cerr<<"\n";for(const vector&vb:vvb){for(const bool&b:vb)cerr<<(b?".":"#");cerr<<"\n";}} void _debug(int,s){}templatevoid _debug(int n,s S,const H&h,const T&... t){int i=0,cnt=0;for(;iap;mint re=a;for(long long r=1;r> N >> K; vector As(N); for (int i = 0; i < N; i++) { cin >> As[i]; } if (K == 1) { cout << *max_element(As.begin(), As.end()) << endl; return 0; } long long temp = 0; // 小さいものから順にpopされる priority_queue, greater> q; vector temps(N); for (int i = N - 1; i >= 0; i--) { q.push(As[i]); temp += As[i]; if (int(q.size()) > K - 1) { temp -= q.top(); q.pop(); } temps[i] = temp; } temps.push_back(-INFll); long long ans = 0; for (int i = 1; i < N; i += 2) { int left = N - i - 1; if (left < K - 1) { continue; } chmax(ans, temps[i + 1] + As[i]); } cout << ans << endl; return 0; }