結果
| 問題 | No.617 Nafmo、買い出しに行く | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-18 23:08:25 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 69 ms / 2,000 ms | 
| コード長 | 443 bytes | 
| コンパイル時間 | 690 ms | 
| コンパイル使用メモリ | 72,584 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-16 00:53:47 | 
| 合計ジャッジ時間 | 2,126 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < 1 << n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        sum += a[j];
      }
    }
    if (sum <= k) {
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
}
            
            
            
        