結果

問題 No.2028 Even Choice
ユーザー guud222guud222
提出日時 2022-08-05 23:22:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 952 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 177,204 KB
実行使用メモリ 14,632 KB
最終ジャッジ日時 2023-10-14 01:15:38
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
10,144 KB
testcase_01 AC 113 ms
12,180 KB
testcase_02 AC 67 ms
8,612 KB
testcase_03 AC 81 ms
14,632 KB
testcase_04 AC 72 ms
13,364 KB
testcase_05 AC 19 ms
5,172 KB
testcase_06 WA -
testcase_07 AC 24 ms
5,632 KB
testcase_08 AC 31 ms
5,412 KB
testcase_09 AC 64 ms
9,080 KB
testcase_10 AC 29 ms
6,248 KB
testcase_11 WA -
testcase_12 AC 5 ms
4,356 KB
testcase_13 AC 98 ms
11,672 KB
testcase_14 AC 15 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,348 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 1 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 28 ms
4,644 KB
testcase_29 AC 19 ms
4,352 KB
testcase_30 AC 13 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vector<PII> a(n + 1);
    vector<int> b(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first;
        a[i].second = i;
        b[i] = a[i].first;
    }
    a[1] = {0, 1};
    sort(a.begin() + 1, a.end(), [&](PII a, PII b){
        if (a.first != b.first) return a.first > b.first;
        return a.second < b.second;
    });
    ll sum = 0;
    set<PII> s;
    for (int i = 1; i <= k; i++) {
        sum += a[i].first;
        s.insert({a[i].second, a[i].first});
    }
    int cur = k + 1;
    while (s.begin()->first % 2 != 0) {
        sum -= s.begin()->second;
        s.erase(s.begin());
        s.insert({a[cur].second, a[cur].first});
        sum += a[cur].first;
        cur++;
    }
    cout << sum << '\n';
    return 0;
}
0