結果

問題 No.2329 Nafmo、イカサマをする
ユーザー dyktr_06dyktr_06
提出日時 2023-04-28 17:27:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 211,288 KB
実行使用メモリ 27,788 KB
最終ジャッジ日時 2024-04-30 02:58:27
合計ジャッジ時間 4,263 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 21 ms
8,096 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 25 ms
9,120 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 28 ms
9,772 KB
testcase_24 AC 11 ms
5,904 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 34 ms
11,060 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 7 ms
5,376 KB
testcase_34 AC 11 ms
5,896 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 52 ms
14,924 KB
testcase_37 AC 19 ms
7,456 KB
testcase_38 AC 106 ms
27,656 KB
testcase_39 AC 107 ms
27,664 KB
testcase_40 AC 106 ms
27,660 KB
testcase_41 AC 118 ms
27,788 KB
testcase_42 AC 107 ms
27,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int n, k;
long long m;

long long solve(vector<long long> &a, vector<long long> &b){
    long long res = 0;
    for(auto x : a){
        if(x > m) continue;
        res = max(res, x);
        auto iter = upper_bound(b.begin(), b.end(), m - x);
        if(iter == b.begin()) continue;
        iter--;
        res = max(res, x + *iter);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m >> k;
    vector<long long> a(n + 1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    a[n] = 0;
    sort(a.begin(), a.end());

    vector<vector<long long>> b(4);
    vector<long long> c = a;
    b[0] = {0};
    b[1] = c;
    for(int i = 2; i <= 3; i++){
        vector<long long> tmp;
        for(auto x : c){
            for(auto y : a){
                tmp.push_back(x + y);
            }
        }
        c = tmp;
        b[i] = c;
        sort(b[i].begin(), b[i].end());
    }

    long long ans = 0;
    if(k == 1){
        ans = solve(b[1], b[0]);
    }else if(k == 2){
        ans = solve(b[1], b[1]);
    }else if(k == 3){
        ans = solve(b[1], b[2]);
    }else if(k == 4){
        ans = solve(b[2], b[2]);
    }else if(k == 5){
        ans = solve(b[2], b[3]);
    }else if(k == 6){
        ans = solve(b[3], b[3]);
    }
    cout << ans << endl;
}
0