結果

問題 No.2028 Even Choice
ユーザー momoyuumomoyuu
提出日時 2022-08-17 21:30:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,031 bytes
コンパイル時間 3,713 ms
コンパイル使用メモリ 278,772 KB
実行使用メモリ 14,336 KB
最終ジャッジ日時 2024-04-15 09:29:58
合計ジャッジ時間 7,261 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
9,600 KB
testcase_01 AC 192 ms
11,648 KB
testcase_02 AC 133 ms
8,064 KB
testcase_03 AC 149 ms
14,336 KB
testcase_04 AC 146 ms
12,800 KB
testcase_05 AC 30 ms
6,940 KB
testcase_06 AC 121 ms
7,936 KB
testcase_07 AC 38 ms
6,940 KB
testcase_08 AC 70 ms
6,940 KB
testcase_09 AC 110 ms
8,704 KB
testcase_10 AC 38 ms
6,940 KB
testcase_11 AC 21 ms
6,944 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 136 ms
11,392 KB
testcase_14 AC 31 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 60 ms
6,944 KB
testcase_29 AC 40 ms
6,944 KB
testcase_30 AC 28 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class t> using vc = vector<t>;
template<class t> using vvc = vc<vc<t>>;
using pi = pair<int,int>;
using vi = vc<int>;
using vvi = vvc<int>;

#define rep(i,a,b) for (int i = a; i < b; i++)
#define irep(i,a,b) for (int i = a; i > b; i--)
#define print(n) cout << n << endl
#define rup(a,b) (a+b-1)/b


int main(){
    cout << fixed << setprecision(15);
    
    int N,K;
    cin >> N >> K;
    vc<ll> A(N,0);
    rep(i,0,N) cin >> A[i];
    ll ans = 0;
    multiset<ll> d;
    ll aa = 0;

    int now = 1;
    irep(i,A.size()-1,0){
        if (now <= K-1){
            now++;
            ans += A[i];
            d.insert(A[i]);
            continue;
        }
        if (i%2 == 1){
            aa = max(ans+A[i],aa);
        }
        d.insert(A[i]);
        ll b = *d.begin();
        ans += A[i] - b;
        d.erase(d.begin());
    }

    print(aa);
    
    //system("pause");
    return 0;
}
0