結果

問題 No.2370 He ate many cakes
ユーザー merom686merom686
提出日時 2023-07-03 21:14:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 205,064 KB
実行使用メモリ 12,316 KB
最終ジャッジ日時 2023-09-24 18:19:25
合計ジャッジ時間 5,109 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 155 ms
5,996 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 14 ms
4,380 KB
testcase_11 AC 57 ms
4,448 KB
testcase_12 AC 227 ms
7,572 KB
testcase_13 AC 297 ms
8,616 KB
testcase_14 AC 101 ms
4,644 KB
testcase_15 AC 431 ms
12,316 KB
testcase_16 AC 209 ms
11,480 KB
testcase_17 AC 327 ms
12,068 KB
testcase_18 AC 24 ms
6,204 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n, k;
    cin >> n >> k;

    vector<ll> x;
    x.push_back(0);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        int l = x.size();
        x.resize(l * 2);
        for (int i = 0; i < l; i++) {
            x[l + i] = x[i] + a;
        }
        l *= 2;
        if (l > k) {
            sort(x.begin(), x.end(), greater<>());
            x.resize(k);
        }
    }
    sort(x.begin(), x.end(), greater<>());
    cout << x.back() << endl;

    return 0;
}
0