結果

問題 No.2329 Nafmo、イカサマをする
ユーザー pockynypockyny
提出日時 2023-05-28 15:27:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 86,092 KB
実行使用メモリ 7,512 KB
最終ジャッジ日時 2023-08-27 12:10:35
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const int B = 3;
ll a[110];
vector<ll> v[2];
void dfs(int pos,int n,int cnt,int num, int id,ll sum){
    if(pos==n){
        v[id].push_back(sum);
    }else{
        dfs(pos + 1,n,cnt,num,id,sum);
        if(cnt + 1<=num) dfs(pos,n,cnt + 1,num,id,sum + a[pos]);
    }
}

int main(){
    ll i,j,l,n,m,k; cin >> n >> m >> k;
    for(i=0;i<n;i++) cin >> a[i];
    if(k<=B){
        dfs(0,n,0,k,0,0);
        sort(v[0].rbegin(),v[0].rend());
        for(i=0;i<v[0].size();i++){
            if(v[0][i]<=m){
                cout << v[0][i] << endl;
                return 0;
            }
        }
    }else{
        dfs(0,n,0,B,0,0);
        dfs(0,n,0,k - B,1,0);
        sort(v[0].begin(),v[0].end());
        sort(v[1].begin(),v[1].end());
        ll ans = 0;
        for(ll x:v[0]){
            int pos = upper_bound(v[1].begin(),v[1].end(),m - x) - v[1].begin();
            pos--;
            if(pos>=0) ans = max(ans,x + v[1][pos]);
        }
        cout << ans << "\n";
    }
}
0