結果

問題 No.2028 Even Choice
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-13 03:46:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 902 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 110,872 KB
実行使用メモリ 13,872 KB
最終ジャッジ日時 2023-08-19 08:32:31
合計ジャッジ時間 9,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
13,732 KB
testcase_01 AC 146 ms
11,468 KB
testcase_02 AC 118 ms
7,824 KB
testcase_03 AC 140 ms
13,872 KB
testcase_04 AC 129 ms
12,652 KB
testcase_05 AC 28 ms
4,836 KB
testcase_06 AC 107 ms
7,744 KB
testcase_07 AC 35 ms
5,352 KB
testcase_08 AC 60 ms
4,932 KB
testcase_09 AC 97 ms
8,820 KB
testcase_10 AC 35 ms
5,928 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 113 ms
11,204 KB
testcase_14 AC 27 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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 (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