結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 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 3 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 5 ms
5,376 KB
testcase_19 AC 20 ms
8,204 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 24 ms
9,120 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 28 ms
9,896 KB
testcase_24 AC 11 ms
5,772 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 8 ms
5,376 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 33 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,772 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 56 ms
18,784 KB
testcase_37 AC 18 ms
7,580 KB
testcase_38 AC 101 ms
27,660 KB
testcase_39 AC 108 ms
27,660 KB
testcase_40 AC 104 ms
27,656 KB
testcase_41 AC 127 ms
35,568 KB
testcase_42 AC 103 ms
27,792 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(3);
    vector<long long> c = a;
    b[0] = c;
    for(int i = 1; i <= 2; 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[0], {0});
    }else if(k == 2){
        ans = solve(b[0], b[0]);
    }else if(k == 3){
        ans = solve(b[0], b[1]);
    }else if(k == 4){
        ans = solve(b[1], b[1]);
    }else if(k == 5){
        ans = solve(b[1], b[2]);
    }else if(k == 6){
        ans = solve(b[2], b[2]);
    }
    cout << ans << endl;
}
0