結果

問題 No.2028 Even Choice
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-13 03:55:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 111,132 KB
実行使用メモリ 13,940 KB
最終ジャッジ日時 2023-08-19 08:36:50
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
9,380 KB
testcase_01 AC 151 ms
11,616 KB
testcase_02 AC 117 ms
7,872 KB
testcase_03 AC 140 ms
13,940 KB
testcase_04 AC 129 ms
12,504 KB
testcase_05 AC 28 ms
4,864 KB
testcase_06 AC 107 ms
7,496 KB
testcase_07 AC 35 ms
5,376 KB
testcase_08 AC 60 ms
4,960 KB
testcase_09 AC 98 ms
8,728 KB
testcase_10 AC 36 ms
5,912 KB
testcase_11 AC 18 ms
4,384 KB
testcase_12 AC 8 ms
4,384 KB
testcase_13 AC 116 ms
11,240 KB
testcase_14 AC 26 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 51 ms
4,380 KB
testcase_29 AC 34 ms
4,380 KB
testcase_30 AC 23 ms
4,384 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);
            }
        }
        if (K == 1) continue;
        if (st.size() < K-1){
            st.insert(A[i]);
            S += A[i];
        }
        else{
            mi = *st.begin();
            if (mi < A[i]){
                S += A[i] - mi;
                st.erase(st.begin());
                st.insert(A[i]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0