結果

問題 No.617 Nafmo、買い出しに行く
ユーザー Nafmo2Nafmo2
提出日時 2017-12-03 10:36:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 335 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 66,176 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 08:41:42
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
int N,K,A[21],sum=-1;
int main(){
    cin>>N>>K;
    REP(i,N)cin>>A[i];
    REP(Bit,1<<N){
        int temp=0;
        REP(i,N)if(Bit&(1<<i))temp+=A[i];
        if(temp<=K)sum=max(sum,temp);
    }
    cout<<sum<<endl;
    return 0;
}
0