結果

問題 No.2364 Knapsack Problem
ユーザー KoseTKoseT
提出日時 2023-06-30 21:54:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 965 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 200,960 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 15:50:21
合計ジャッジ時間 3,269 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 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 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 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=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';
}
0