結果

問題 No.2741 Balanced Choice
ユーザー tobbietobbie
提出日時 2024-04-26 17:01:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 170,244 KB
実行使用メモリ 101,504 KB
最終ジャッジ日時 2024-04-26 17:01:51
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 141 ms
101,120 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi = vector<int>;
using vvi = vector<vi>;

struct Stone {
  int w;
  int v;
  Stone(int w, int v) : w(w), v(v) {}
};

int main() {
  int N, W, D;
  cin >> N >> W >> D;
  vector<Stone> s0, s1;
  rep(i, N) {
    int ti, wi, vi;
    cin >> ti >> wi >> vi;
    if (ti == 0)
      s0.push_back({wi, vi});
    if (ti == 1)
      s1.push_back({wi, vi});
  }
  int n0 = (int)s0.size();
  int n1 = (int)s1.size();
  vvi dp0(n0+1, vi (W+1, 0));
  vvi dp1(n1+1, vi (W+1, 0));
  auto f = [&](int n, int m, vvi & dp, vector<Stone> &s) {
    rep(i, n) {
      rep(j, m+1) {
	if (j >= s[i].w)
	  dp[i+1][j] = max(dp[i][j - s[i].w] + s[i].v, dp[i][j]);
	else
	  dp[i+1][j] = dp[i][j];
      }
    }
  };
  f(n0, W, dp0, s0);
  f(n1, W, dp1, s1);
  int m = 0;
  rep(i, W+1) rep(j, W+1-i) {
    if (abs(dp0[n0][i] - dp1[n1][j]) <= D)
      m = max(dp0[n0][i] + dp1[n1][j], m);
  }
  cout << m << endl;
  return 0;
}
0