結果

問題 No.617 Nafmo、買い出しに行く
ユーザー Konton7
提出日時 2020-01-14 01:13:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 192,092 KB
最終ジャッジ日時 2025-01-08 17:52:16
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;


int main(){
    int n, w, x, y, ans;
    cin >> n >> w;
    int a[n] = {};
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    ans = 0;
    for (int i = 0; i < pow(2, n); i++){
        x = i;
        y = 0;
        for (int j = 0; j < n; j++){
            y += a[j] * (x % 2);
            x >>= 1;
        }
        if (y <= w)
            ans = max(y, ans);
    }
    cout << ans << endl;
    
    return 0;

}
0