結果

問題 No.2028 Even Choice
ユーザー baLoon8128baLoon8128
提出日時 2022-08-05 21:33:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 3,695 ms
コンパイル使用メモリ 228,832 KB
実行使用メモリ 6,040 KB
最終ジャッジ日時 2023-10-13 22:04:38
合計ジャッジ時間 6,225 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
4,820 KB
testcase_01 AC 86 ms
5,936 KB
testcase_02 AC 89 ms
4,928 KB
testcase_03 AC 81 ms
6,040 KB
testcase_04 AC 82 ms
6,012 KB
testcase_05 AC 19 ms
4,348 KB
testcase_06 AC 80 ms
4,728 KB
testcase_07 AC 23 ms
4,352 KB
testcase_08 AC 55 ms
4,348 KB
testcase_09 AC 61 ms
4,712 KB
testcase_10 AC 23 ms
4,352 KB
testcase_11 AC 16 ms
4,352 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 62 ms
5,712 KB
testcase_14 AC 26 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 48 ms
4,348 KB
testcase_29 AC 32 ms
4,352 KB
testcase_30 AC 22 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

int main() {
    int n, K;
    cin >> n >> K;
    vi a(n);
    rep(i, n) cin >> a[i];
    ll ret = 0;
    ll s = 0;
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    repr(i, n) {
        if (pq.size() > K - 1) {
            s -= pq.top();
            pq.pop();
        }
        s += a[i];
        pq.emplace(a[i]);
        if (i & 1) ret = max(ret, s);
    }
    cout << ret << endl;
    return 0;
}
0