結果

問題 No.2364 Knapsack Problem
ユーザー D4Cngo_cppD4Cngo_cpp
提出日時 2023-07-01 15:48:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,529 bytes
コンパイル時間 7,404 ms
コンパイル使用メモリ 261,940 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 09:59:30
合計ジャッジ時間 4,841 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define all(a) (a).begin(), (a).end();
//なんかstd::vector<bool>の挙動を修正できるやつ

/* alias */
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
#define debug(x)                                                               \
  cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m"  \
       << endl;
const ll minf = -1e10;
int main() {
  int n, m, w;
  cin >> n >> m >> w;
  vll a(n + 1), b(n + 1), c(m + 1), d(m + 1);
  rep(i, n) cin >> a[i + 1];
  rep(i, n) cin >> b[i + 1];
  rep(i, m) cin >> c[i + 1];
  rep(i, m) cin >> d[i + 1];
  vvll dp(n + 1, vll(w + 1, minf));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= w; j++) {
      if (j < a[i]) {
        dp[i][j] = dp[i - 1][j];

      } else if (j <= w)
        dp[i][j] = max(dp[i - 1][j - a[i]] + b[i], dp[i - 1][j]);

      for (int k = 1; k <= m; k++) {
        if (j - c[k] >= 0)
          dp[i][j - c[k]] = max(dp[i][j - c[k]], dp[i][j] - d[k]);
      }
    }
  }
  ll ans = -1000;
  rep(i, w + 1) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
0