結果

問題 No.2329 Nafmo、イカサマをする
ユーザー Ryoga.exeRyoga.exe
提出日時 2023-05-28 16:15:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 2,105 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 206,084 KB
実行使用メモリ 12,044 KB
最終ジャッジ日時 2023-08-27 13:49:35
合計ジャッジ時間 4,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 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 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 19 ms
5,044 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 22 ms
5,120 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 25 ms
8,200 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 29 ms
7,720 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 9 ms
4,380 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 44 ms
7,984 KB
testcase_37 AC 16 ms
5,048 KB
testcase_38 AC 88 ms
11,712 KB
testcase_39 AC 90 ms
12,044 KB
testcase_40 AC 88 ms
11,604 KB
testcase_41 AC 101 ms
11,900 KB
testcase_42 AC 89 ms
11,952 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() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a1(n + 1);
    for (ll i = 0; i < n; i++) {
        cin >> a1[i];
    }
    n++;
    sort(a1.begin(), a1.end());
    vector<ll> a2;
    for (ll i = 0; i < n; i++) {
        for (ll id = 0; id < n; id++) {
            a2.push_back(a1[i] + a1[id]);
        }
    }
    sort(a2.begin(), a2.end());
    vector<ll> a3;
    for (ll i = 0; i < n; i++) {
        for (ll id = 0; id < n; id++) {
            for (ll 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) {
        ll ans = 0;
        for (ll 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) {
        ll ans = 0;
        for (ll 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 {
        ll ans = 0;
        for (ll 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