結果
| 問題 |
No.2364 Knapsack Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 21:54:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 965 bytes |
| コンパイル時間 | 1,894 ms |
| コンパイル使用メモリ | 195,956 KB |
| 最終ジャッジ日時 | 2025-02-15 03:48:24 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, w;
cin >> n >> m >> w;
vector<pair<int, long long>> merch(n);
for (int i=0;i<n;++i) cin >> merch[i].first;
for (int i=0;i<n;++i) cin >> merch[i].second;
vector<pair<int, long long>> magic(m);
for (int i=0;i<m;++i) cin >> magic[i].first;
for (int i=0;i<m;++i) cin >> magic[i].second;
long long ans {};
for (int i=0;i<(1<<(n+m));++i) {
pair<int, long long> ans_tmp {};
for (int j=0;j<n;++j) {
if (i & (1<<j)) {
ans_tmp.first += merch[j].first;
ans_tmp.second += merch[j].second;
}
}
for (int j=n;j<n+m;++j) {
if (i & (1<<j)) {
ans_tmp.first -= magic[j-n].first;
ans_tmp.second -= magic[j-n].second;
}
}
//cout << ans_tmp.first << ' ' << ans_tmp.second << '\n';
if (ans_tmp.first <= w) ans = max(ans, ans_tmp.second);
}
cout << ans << '\n';
}