結果

問題 No.2329 Nafmo、イカサマをする
ユーザー Ryoga.exeRyoga.exe
提出日時 2023-05-28 16:14:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,099 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 206,216 KB
実行使用メモリ 8,284 KB
最終ジャッジ日時 2023-08-27 13:48:24
合計ジャッジ時間 4,703 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 17 ms
4,376 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 21 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 24 ms
5,108 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 7 ms
4,380 KB
testcase_27 AC 6 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 27 ms
5,196 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 9 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 43 ms
5,136 KB
testcase_37 AC 15 ms
4,380 KB
testcase_38 AC 85 ms
7,728 KB
testcase_39 AC 87 ms
8,284 KB
testcase_40 AC 86 ms
8,000 KB
testcase_41 AC 99 ms
7,416 KB
testcase_42 AC 87 ms
7,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a1(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a1[i];
    }
    n++;
    sort(a1.begin(), a1.end());
    vector<int> a2;
    for (int i = 0; i < n; i++) {
        for (int id = 0; id < n; id++) {
            a2.push_back(a1[i] + a1[id]);
        }
    }
    sort(a2.begin(), a2.end());
    vector<int> a3;
    for (int i = 0; i < n; i++) {
        for (int id = 0; id < n; id++) {
            for (int idx = 0; idx < n; idx++) {
                a3.push_back(a1[i] + a1[id] + a1[idx]);
            }
        }
    }
    sort(a3.begin(), a3.end());
    if (k == 1) {
        cout << *prev(upper_bound(a1.begin(), a1.end(), m)) << endl;
    }
    else if (k == 2) {
        cout << *prev(upper_bound(a2.begin(), a2.end(), m)) << endl;
    }
    else if (k == 3) {
        cout << *prev(upper_bound(a3.begin(), a3.end(), m)) << endl;
    }
    else if (k == 4) {
        int ans = 0;
        for (int i = 0; i < a2.size(); i++) {
            if (a2[i] > m) {
                continue;
            }
            auto key = m - a2[i];
            auto it = prev(upper_bound(a2.begin(), a2.end(), key));
            chmax(ans, a2[i] + *it);
        }
        cout << ans << endl;
    }
    else if (k == 5) {
        int ans = 0;
        for (int i = 0; i < a2.size(); i++) {
            if (a2[i] > m) {
                continue;
            }
            auto key = m - a2[i];
            auto it = prev(upper_bound(a3.begin(), a3.end(), key));
            chmax(ans, a2[i] + *it);
        }
        cout << ans << endl;
    }
    else {
        int ans = 0;
        for (int i = 0; i < a3.size(); i++) {
            if (a3[i] > m) {
                continue;
            }
            auto key = m - a3[i];
            auto it = prev(upper_bound(a3.begin(), a3.end(), key));
            chmax(ans, a3[i] + *it);
        }
        cout << ans << endl;
    }
    return 0;
}
0