結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
10,092 KB
testcase_01 AC 103 ms
12,212 KB
testcase_02 AC 65 ms
8,620 KB
testcase_03 AC 78 ms
14,696 KB
testcase_04 AC 71 ms
13,504 KB
testcase_05 AC 19 ms
5,176 KB
testcase_06 WA -
testcase_07 AC 24 ms
5,716 KB
testcase_08 AC 31 ms
5,392 KB
testcase_09 AC 64 ms
9,152 KB
testcase_10 AC 28 ms
6,216 KB
testcase_11 WA -
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 89 ms
11,712 KB
testcase_14 AC 15 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 29 ms
4,628 KB
testcase_29 AC 19 ms
4,352 KB
testcase_30 AC 13 ms
4,348 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());
        sum += a[cur].first;
        s.insert({a[cur].second, a[cur].first});
        cur++;
    }
    cout << sum << '\n';
    return 0;
}
0