結果

問題 No.2028 Even Choice
ユーザー erbowlerbowl
提出日時 2022-08-06 05:47:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 207,492 KB
実行使用メモリ 10,232 KB
最終ジャッジ日時 2023-10-14 07:37:57
合計ジャッジ時間 6,768 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
9,864 KB
testcase_01 AC 119 ms
9,788 KB
testcase_02 AC 121 ms
10,160 KB
testcase_03 AC 117 ms
9,256 KB
testcase_04 AC 112 ms
9,892 KB
testcase_05 AC 26 ms
4,524 KB
testcase_06 AC 107 ms
10,232 KB
testcase_07 AC 31 ms
4,628 KB
testcase_08 AC 73 ms
6,184 KB
testcase_09 AC 84 ms
8,724 KB
testcase_10 AC 31 ms
4,604 KB
testcase_11 AC 22 ms
4,352 KB
testcase_12 AC 9 ms
4,348 KB
testcase_13 AC 91 ms
9,004 KB
testcase_14 AC 33 ms
4,516 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 3 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 57 ms
6,240 KB
testcase_29 AC 39 ms
5,740 KB
testcase_30 AC 26 ms
4,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ll n,k;
    std::cin >> n>>k;
    vector<ll> a(n);
    ll tsum = 0;
    typedef pair<ll,ll> pll;
    priority_queue<pll> pq;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        tsum += a[i];
        if(i>1){
            pq.push({a[i],i});
        }
    }
    ll sum = 0;
    vector<bool> used(n);
    for (int i = 0; i < k-1; i++) {
        auto [ai,ind] = pq.top();pq.pop();
        sum += ai;
        used[ind]=true;
    }
    ll ans = 0;
    for (int i = 0; i < n/2&&2*i+1<n-(k-1); i++) {
        for (int j = 2*i; j < 2*i+2; j++) {
            if(used[j]){
                sum -= a[j];
                while(true){
                    auto [ai,ind] = pq.top();pq.pop();
                    if(ind<=2*i+1)continue;
                    used[ind]=true;
                    sum += ai;
                    break;
                }
            }
        }
        ans = max(ans, a[2*i+1]+sum);
    }
    std::cout << ans << std::endl;
}
0