結果

問題 No.2741 Balanced Choice
ユーザー KudeKude
提出日時 2024-04-21 10:23:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 4,056 ms
コンパイル使用メモリ 300,284 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 10:23:36
合計ジャッジ時間 5,119 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w, d;
  cin >> n >> w >> d;
  vector<int> dp0(w + 1, -1), dp1(w + 1, -1);
  dp0[0] = dp1[0] = 0;
  rep(_, n) {
    int t, wi, vi;
    cin >> t >> wi >> vi;
    auto& dp = t ? dp1 : dp0;
    rrep(i, w - wi + 1) if (dp[i] != -1) chmax(dp[i + wi], dp[i] + vi);
  }
  int ans = 0;
  segtree<int, [](int x, int y) { return max(x, y); }, []() { return -1; }> seg(dp1);
  rep(i, w + 1) if (dp0[i] != -1) {
    int li = max(0, i - d), ri = min(w - i, i + d);
    if (li <= ri) {
      int mx = seg.prod(li, ri + 1);
      if (mx != -1) chmax(ans, dp0[i] + mx);
    }
  }
  cout << ans << '\n';
}
0