結果

問題 No.2741 Balanced Choice
ユーザー t98slidert98slider
提出日時 2024-04-20 13:49:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 4,534 ms
コンパイル使用メモリ 255,696 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 13:49:11
合計ジャッジ時間 4,666 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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';
}
0