結果
問題 |
No.2741 Balanced Choice
|
ユーザー |
|
提出日時 | 2024-04-20 13:49:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 877 bytes |
コンパイル時間 | 4,631 ms |
コンパイル使用メモリ | 253,760 KB |
最終ジャッジ日時 | 2025-02-21 06:31:50 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; int op(int lhs, int rhs){ return max(lhs, rhs); } int e(){ return -(1 << 29); } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, W, D, t, w, v, ans = 0; cin >> n >> W >> D; vector<vector<int>> dp(2, vector<int>(W + 1, -(1 << 30))); dp[0][0] = dp[1][0] = 0; while(n--){ cin >> t >> w >> v; for(int i = W - w; i >= 0; i--){ dp[t][i + w] = max(dp[t][i + w], dp[t][i] + v); } } atcoder::segtree<int, op, e> seg0(dp[0]); atcoder::segtree<int, op, e> seg1(dp[1]); for(int i = 0; i <= W; i++){ int l = max(0, i - D), r = min(i + D, W - i) + 1; if(l >= r) break; ans = max(ans, dp[0][i] + seg1.prod(l, r)); ans = max(ans, dp[1][i] + seg0.prod(l, r)); } cout << ans << '\n'; }