結果

問題 No.2028 Even Choice
ユーザー ruthenruthen
提出日時 2022-08-05 21:56:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 203,720 KB
実行使用メモリ 6,632 KB
最終ジャッジ日時 2023-10-13 22:42:30
合計ジャッジ時間 4,050 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
5,572 KB
testcase_01 AC 38 ms
6,632 KB
testcase_02 AC 42 ms
5,668 KB
testcase_03 AC 31 ms
6,624 KB
testcase_04 AC 32 ms
6,624 KB
testcase_05 AC 9 ms
4,352 KB
testcase_06 AC 38 ms
5,484 KB
testcase_07 AC 11 ms
4,348 KB
testcase_08 AC 25 ms
4,556 KB
testcase_09 AC 28 ms
5,264 KB
testcase_10 AC 10 ms
4,348 KB
testcase_11 AC 8 ms
4,352 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 26 ms
6,360 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 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 2 ms
4,348 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 19 ms
4,348 KB
testcase_29 AC 13 ms
4,352 KB
testcase_30 AC 10 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, K;
    cin >> N >> K;
    V<ll> A(N);
    rep(i, N) cin >> A[i];
    priority_queue<ll, vector<ll>, greater<ll>> que;
    ll cs = 0, ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (i % 2 != 0) {
            // A[i] と K-1個
            while (que.size() > K - 1) {
                cs -= que.top();
                que.pop();
            }
            ans = max(ans, cs + A[i]);
        }
        que.push(A[i]);
        cs += A[i];
    }
    cout << ans << '\n';
    return 0;
}
0