結果

問題 No.2028 Even Choice
ユーザー Carpenters-Cat
提出日時 2022-08-05 23:52:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 198,728 KB
最終ジャッジ日時 2025-01-30 18:53:33
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    ll sum = 0;
    priority_queue<ll, vector<ll>, greater<ll>> pque;
    ll ans = 0;
    for (int i = 1; i < K; i ++) {
        pque.push(A[N - i]);
        sum += A[N - i];
    }
    for (int i = N - K; i >= 0; i --) {
        if (i % 2) {
            ans = max(ans, A[i] + sum);
        }
        sum += A[i];
        pque.push(A[i]);
        sum -= pque.top();
        pque.pop();
    }
    cout << ans << endl;
}
0