結果

問題 No.2028 Even Choice
ユーザー guud222guud222
提出日時 2022-08-05 23:02:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,163 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 175,864 KB
実行使用メモリ 13,820 KB
最終ジャッジ日時 2023-10-14 00:45:04
合計ジャッジ時間 4,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 101 ms
11,524 KB
testcase_02 AC 64 ms
7,732 KB
testcase_03 AC 84 ms
13,820 KB
testcase_04 AC 75 ms
12,552 KB
testcase_05 AC 18 ms
4,940 KB
testcase_06 WA -
testcase_07 AC 23 ms
5,628 KB
testcase_08 AC 31 ms
4,900 KB
testcase_09 AC 61 ms
8,540 KB
testcase_10 AC 27 ms
5,920 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 96 ms
11,232 KB
testcase_14 AC 14 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 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 2 ms
4,352 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 30 ms
4,352 KB
testcase_29 AC 19 ms
4,348 KB
testcase_30 AC 13 ms
4,352 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);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    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<int> s;
    for (int i = 1; i <= k; i++) {
        sum += a[i].first;
        s.insert(a[i].second);
    }
    if (*s.begin() % 2 == 0) {
        cout << sum << '\n';
    } else {
        auto it = next(s.begin());
        int x = n + 1;
        if (it != s.end()) {
            x = *it;
        }
        int mx = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i].second % 2 == 0 and a[i].second < x) {
                mx = max(mx, a[i].first);
            } 
            if (a[i].second == *s.begin()) {
                sum -= a[i].first;
            }
        }
        sum += mx;
        cout << sum << '\n';
    }
    return 0;
}
0