結果
問題 |
No.2364 Knapsack Problem
|
ユーザー |
![]() |
提出日時 | 2023-06-30 21:25:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 788 bytes |
コンパイル時間 | 1,954 ms |
コンパイル使用メモリ | 195,240 KB |
最終ジャッジ日時 | 2025-02-15 03:28:20 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n, m, w; cin >> n >> m >> w; vector<int> a(n), b(n), c(m), d(m); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, m) cin >> c[i]; rep(i, m) cin >> d[i]; ll ans = 0; rep(bit, 1 << (n + m)) { int wei = 0; ll val = 0; rep(i, n) { if (bit & (1 << i)) { wei += a[i]; val += b[i]; } } rep(i, m) { if (bit & (1 << (n + i))) { wei -= c[i]; val -= d[i]; } } if (0 <= wei && wei <= w) ans = max(ans, val); } cout << ans << endl; return 0; }