結果

問題 No.2028 Even Choice
ユーザー ぷらぷら
提出日時 2022-08-05 21:26:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 204,028 KB
実行使用メモリ 4,992 KB
最終ジャッジ日時 2023-10-13 21:49:30
合計ジャッジ時間 4,619 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
4,400 KB
testcase_01 AC 84 ms
4,916 KB
testcase_02 AC 86 ms
4,524 KB
testcase_03 AC 80 ms
4,984 KB
testcase_04 AC 80 ms
4,992 KB
testcase_05 AC 19 ms
4,348 KB
testcase_06 AC 76 ms
4,352 KB
testcase_07 AC 22 ms
4,352 KB
testcase_08 AC 53 ms
4,352 KB
testcase_09 AC 60 ms
4,364 KB
testcase_10 AC 21 ms
4,348 KB
testcase_11 AC 16 ms
4,348 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 61 ms
4,612 KB
testcase_14 AC 25 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,356 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 47 ms
4,348 KB
testcase_29 AC 31 ms
4,348 KB
testcase_30 AC 22 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N,K;
    cin >> N >> K;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long ans = 0,sum = 0;
    priority_queue<int,vector<int>,greater<int>>que;
    for(int i = N-1; i >= 0; i--) {
        if(i%2 == 1) {
            ans = max(ans,sum+A[i]);
        }
        sum += A[i];
        que.push(A[i]);
        if(que.size() == K) {
            sum -= que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}
0