結果
| 問題 |
No.617 Nafmo、買い出しに行く
|
| コンテスト | |
| ユーザー |
kichirb3
|
| 提出日時 | 2018-03-02 18:17:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,317 bytes |
| コンパイル時間 | 724 ms |
| コンパイル使用メモリ | 81,712 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-11 18:21:53 |
| 合計ジャッジ時間 | 1,671 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 WA * 6 |
ソースコード
// No.617 Nafmo、買い出しに行く
// https://yukicoder.me/problems/no/617
//
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
int calc_total(vector<int> &items, int i);
int main() {
int N, K;
cin >> N >> K;
vector<int> items_a;
vector<int> items_b;
for (auto i = 0; i < N; ++i) {
int tmp;
cin >> tmp;
if (i < N/2)
items_a.push_back(tmp);
else
items_b.push_back(tmp);
}
vector<int> total_a;
for (auto i = 0; i < (1 << items_a.size()); ++i) {
int total = calc_total(items_a, i);
total_a.push_back(total);
}
vector<int> total_b;
for (auto i = 0; i < (1 << items_b.size()); ++i) {
int total = calc_total(items_b, i);
total_b.push_back(total);
}
int max_total = 0;
sort(total_b.begin(), total_b.end());
for (auto a: total_a) {
auto itr = upper_bound(total_b.begin(), total_b.end(), K-a);
int ans = a + *(--itr);
max_total = max(max_total, ans);
}
cout << max_total << endl;
}
int calc_total(vector<int> &items, int i) {
int total = 0;
for (auto j = 0; j < items.size(); j++) {
if (i & (1<<j)) {
total += items[j];
}
}
return total;
}
kichirb3