結果
問題 |
No.617 Nafmo、買い出しに行く
|
ユーザー |
![]() |
提出日時 | 2018-03-02 13:01:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 814 bytes |
コンパイル時間 | 855 ms |
コンパイル使用メモリ | 71,712 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-01-02 16:59:09 |
合計ジャッジ時間 | 2,246 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
// No.617 Nafmo、買い出しに行く // https://yukicoder.me/problems/no/617 // #include <iostream> #include <vector> #include <iomanip> #include <numeric> using namespace std; int calc_total(vector<int> &items, int i); int main() { int N, K; cin >> N >> K; vector<int> items; for (auto i = 0; i < N; ++i) { int tmp; cin >> tmp; items.push_back(tmp); } int total_max = 0; for (auto i = 0; i < (1<<N); ++i) { int total = calc_total(items, i); if (total <= K) total_max = max(total_max, total); } cout << total_max << endl; } int calc_total(vector<int> &items, int i) { int total = 0; for (auto j = 0; j < 20; j++) { if (i & (1<<j)) { total += items[j]; } } return total; }