結果

問題 No.2028 Even Choice
ユーザー atjh16atjh16
提出日時 2022-08-12 08:32:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 2,891 ms
コンパイル使用メモリ 205,456 KB
実行使用メモリ 8,256 KB
最終ジャッジ日時 2023-10-23 19:00:03
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
7,344 KB
testcase_01 AC 92 ms
8,136 KB
testcase_02 AC 94 ms
7,080 KB
testcase_03 AC 91 ms
8,256 KB
testcase_04 AC 90 ms
8,136 KB
testcase_05 AC 21 ms
6,184 KB
testcase_06 AC 84 ms
6,912 KB
testcase_07 AC 26 ms
6,256 KB
testcase_08 AC 57 ms
6,512 KB
testcase_09 AC 67 ms
7,012 KB
testcase_10 AC 25 ms
6,416 KB
testcase_11 AC 18 ms
6,112 KB
testcase_12 AC 8 ms
5,856 KB
testcase_13 AC 69 ms
8,052 KB
testcase_14 AC 26 ms
6,272 KB
testcase_15 AC 2 ms
5,720 KB
testcase_16 AC 3 ms
5,660 KB
testcase_17 AC 2 ms
5,720 KB
testcase_18 AC 2 ms
5,720 KB
testcase_19 AC 2 ms
5,724 KB
testcase_20 AC 3 ms
5,732 KB
testcase_21 AC 2 ms
5,736 KB
testcase_22 AC 3 ms
5,732 KB
testcase_23 AC 2 ms
5,660 KB
testcase_24 AC 2 ms
5,720 KB
testcase_25 AC 2 ms
5,660 KB
testcase_26 AC 2 ms
5,720 KB
testcase_27 AC 2 ms
5,660 KB
testcase_28 AC 53 ms
6,328 KB
testcase_29 AC 36 ms
6,320 KB
testcase_30 AC 25 ms
6,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long n, k, m;
long long a[200000], d[200000];
priority_queue<long long, vector<long long>, greater<long long>> Q;

int main() {    
    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = n - 1; i > 0; i--) {
        d[i - 1] = d[i];

        if (Q.size() < k - 1) {
            Q.push(a[i]);
            d[i - 1] += a[i];
        }
        else if (Q.size() > 0) {
            long long t = Q.top();

            if (t < a[i]) {
                Q.pop();
                Q.push(a[i]);
                d[i - 1] += a[i] - t;
            }
        }
    }

    for (int i = 1; i < n; i += 2)
        m = max(m, a[i] + d[i]);

    cout << m << endl;
}
0