結果

問題 No.2329 Nafmo、イカサマをする
ユーザー Ryoga.exeRyoga.exe
提出日時 2023-05-28 15:59:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,335 bytes
コンパイル時間 4,042 ms
コンパイル使用メモリ 204,288 KB
実行使用メモリ 8,488 KB
最終ジャッジ日時 2023-08-27 13:33:22
合計ジャッジ時間 4,195 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 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,384 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 20 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 23 ms
5,136 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 27 ms
5,188 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 41 ms
5,256 KB
testcase_37 AC 15 ms
4,376 KB
testcase_38 AC 86 ms
7,388 KB
testcase_39 AC 83 ms
8,444 KB
testcase_40 AC 82 ms
8,068 KB
testcase_41 AC 95 ms
8,332 KB
testcase_42 AC 85 ms
8,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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> a(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    n++;
    vector<int> a2;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            a2.push_back(a[i] + a[j]);
        }
    }
    sort(a2.begin(), a2.end());
    vector<int> a3;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int jj = 0; jj < n; jj++) {
                a3.push_back(a[i] + a[j] + a[jj]);
            }
        }
    }
    sort(a3.begin(), a3.end());
    n++;
    if (k == 1) {
        cout << *prev(upper_bound(a.begin(), a.end(), m)) << endl;
    }
    if (k == 2) {
        cout << *prev(upper_bound(a2.begin(), a2.end(), m)) << endl;
    }
    if (k == 3) {
        int ans = 0;
        for (int i = 0; i < a.size(); i++) {
            if (a[i] > m) {
                continue;
            }
            auto key = m - a[i];
            auto it = prev(upper_bound(a2.begin(), a2.end(), key));
            chmax(ans, a[i] + *it);
        }
        cout << ans << endl;
    }
    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;
    }
    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;
    }
    if (k == 6) {
        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