結果

問題 No.2329 Nafmo、イカサマをする
ユーザー momoyuumomoyuu
提出日時 2023-05-28 14:28:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 2,912 ms
コンパイル使用メモリ 251,592 KB
実行使用メモリ 12,364 KB
最終ジャッジ日時 2023-08-27 09:52:24
合計ジャッジ時間 5,149 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 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,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 24 ms
5,044 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 25 ms
5,400 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 52 ms
8,252 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 104 ms
12,180 KB
testcase_40 AC 117 ms
11,476 KB
testcase_41 AC 144 ms
11,992 KB
testcase_42 AC 117 ms
12,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n);
    for(int i = 0;i<n;i++){
        cin>>a[i];
    }
    a.push_back(0);
    n++;
    vector<ll> use;
    if(k<=3){
        ll ans = 0;
        for(int i = 0;i<n;i++) for(int j = 0;j<n;j++) for(int l = 0;l<n;l++){
            ll now = a[i];
            if(k>=2) now += a[j];
            if(k==3) now += a[l];
            if(now<=m) ans = max(now,ans);
        }
        cout<<ans<<endl;
        return 0;
    }
    for(int i = 0;i<n;i++) for(int j = 0;j<n;j++) for(int l = 0;l<n;l++){
        use.push_back(a[i]+a[j]+a[l]);
    }
    sort(use.begin(),use.end());
    ll ans = 0;
    for(int i = 0;i<n;i++) for(int j = 0;j<n;j++) for(int l = 0;l<n;l++){
        ll now = a[i];
        if(k>=5) now += a[j];
        if(k==6) now += a[l];
        ll want = m - now;
        if(want<0) continue;
        int ni = upper_bound(use.begin(),use.end(),want) - use.begin();
        ni--;
        assert(ni<use.size());
        ll can = now + use[ni];
        if(can<=m) ans = max(ans,can);
    }
    cout<<ans<<endl;
}
0