結果

問題 No.617 Nafmo、買い出しに行く
ユーザー ninoinuininoinui
提出日時 2020-01-23 20:04:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 368 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 166,176 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 08:15:42
合計ジャッジ時間 3,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int ans = 0;
  for (int bit = 0; bit < 1 << N; bit++) {
    int tmp = 0;
    for (int i = 0; i < N; i++) if (bit >> i & 1) tmp += A.at(i);
    ans = (tmp <= K) ? max(ans, tmp) : ans;
  }
  cout << ans << "\n";
}
0