結果

問題 No.2028 Even Choice
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-08-05 23:52:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 204,308 KB
実行使用メモリ 6,664 KB
最終ジャッジ日時 2023-10-14 02:03:31
合計ジャッジ時間 5,077 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
5,708 KB
testcase_01 AC 89 ms
6,644 KB
testcase_02 AC 93 ms
5,620 KB
testcase_03 AC 85 ms
6,664 KB
testcase_04 AC 87 ms
6,592 KB
testcase_05 AC 20 ms
4,348 KB
testcase_06 AC 82 ms
5,452 KB
testcase_07 AC 25 ms
4,352 KB
testcase_08 AC 57 ms
4,352 KB
testcase_09 AC 64 ms
5,212 KB
testcase_10 AC 23 ms
4,348 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 8 ms
4,352 KB
testcase_13 AC 66 ms
6,252 KB
testcase_14 AC 26 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,356 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 51 ms
4,352 KB
testcase_29 AC 34 ms
4,348 KB
testcase_30 AC 23 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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