結果

問題 No.617 Nafmo、買い出しに行く
ユーザー 👑 naipianaipia
提出日時 2018-05-22 01:54:45
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 630 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 153,368 KB
実行使用メモリ 271,456 KB
最終ジャッジ日時 2023-09-11 01:10:28
合計ジャッジ時間 7,313 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 10 ms
4,376 KB
testcase_03 TLE -
testcase_04 AC 1 ms
4,380 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void calc(int const sum, vector<int> const a, int const K, vector<int> &com){
    vector<int> na(a);
    for(int i=0;i<a.size();i++){
        if(sum+na.back()>K) return;
        int tmp=na.back();
        na.pop_back();
        calc(sum, na, K, com);
        calc(sum+tmp, na, K, com);
        com.push_back(sum+tmp);
    }
}

int main(){
    int N,K,in;
    vector<int> a, com;

    cin >> N >> K;
    while(cin >> in) a.push_back(in);
    sort(a.begin(),a.end(),greater<int>());
    calc(0,a,K,com);
    sort(com.begin(),com.end());
    cout << com.back() << endl;

    return 0;
}
0