結果

問題 No.2028 Even Choice
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-13 03:58:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 758 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 112,668 KB
実行使用メモリ 13,984 KB
最終ジャッジ日時 2023-08-19 08:37:54
合計ジャッジ時間 5,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
9,368 KB
testcase_01 AC 151 ms
11,724 KB
testcase_02 AC 125 ms
7,780 KB
testcase_03 AC 138 ms
13,984 KB
testcase_04 AC 140 ms
12,648 KB
testcase_05 AC 30 ms
5,104 KB
testcase_06 AC 124 ms
7,512 KB
testcase_07 AC 36 ms
5,396 KB
testcase_08 AC 66 ms
5,100 KB
testcase_09 AC 123 ms
8,644 KB
testcase_10 AC 39 ms
5,988 KB
testcase_11 AC 19 ms
4,384 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 141 ms
11,156 KB
testcase_14 AC 29 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 56 ms
4,380 KB
testcase_29 AC 37 ms
4,380 KB
testcase_30 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    ll N, K, S=0, ans=0, mi;
    cin >> N >> K;
    multiset<ll> st;
    vector<ll> A(N);

    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=N-1; i>=0; i--){
        if (i % 2 == 1){
            if (st.size() == K-1){
                ans = max(ans, A[i]+S);
            }
        }
        st.insert(A[i]);
        S += A[i];
        if (st.size() == K){
            S -= *st.begin();
            st.erase(st.begin());
        }
    }

    cout << ans << endl;

    return 0;
}
0