結果
| 問題 | No.617 Nafmo、買い出しに行く | 
| コンテスト | |
| ユーザー |  ldsyb | 
| 提出日時 | 2017-12-18 00:01:06 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 68 ms / 2,000 ms | 
| コード長 | 357 bytes | 
| コンパイル時間 | 2,123 ms | 
| コンパイル使用メモリ | 166,484 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-15 23:14:17 | 
| 合計ジャッジ時間 | 3,616 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int a[n];
	for (auto &i : a) {
		cin >> i;
	}
	int ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		int w = 0;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				w += a[j];
			}
		}
		if (w <= k) {
			ans = max(ans, w);
		}
	}
	cout << ans << endl;
	return 0;
}
            
            
            
        