結果

問題 No.2364 Knapsack Problem
ユーザー KoseTKoseT
提出日時 2023-06-30 22:03:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 205,292 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 16:03:52
合計ジャッジ時間 3,350 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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=1;i<(1<<(n+m));++i) {
    pair<int, long long> ans_tmp {};
    vector<int> weights;
    for (int j=0;j<n;++j) {
      if (i & (1<<j)) {
        weights.push_back(merch[j].first);
        ans_tmp.second += merch[j].second;
      }
    }
    for (int j=n;j<n+m;++j) {
      if (i & (1<<j)) {
        weights.push_back(-magic[j-n].first);
        ans_tmp.second -= magic[j-n].second;
      }
    }
    sort(weights.begin(), weights.end());
    if (weights[0] < -w) continue;
    if (w < weights[weights.size()-1]) continue;
    ans_tmp.first = accumulate(weights.begin(), weights.end(), 0ll);
    //cout << ans_tmp.first << ' ' << ans_tmp.second << '\n';
    if (ans_tmp.first <= w) ans = max(ans, ans_tmp.second);
  }
  cout << ans << '\n';
}
0