結果

問題 No.2741 Balanced Choice
ユーザー hiikunZhiikunZ
提出日時 2024-04-20 14:21:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 197,396 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 14:21:04
合計ジャッジ時間 2,991 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
6,816 KB
testcase_01 AC 42 ms
6,944 KB
testcase_02 AC 45 ms
6,940 KB
testcase_03 AC 44 ms
6,944 KB
testcase_04 AC 44 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 23 ms
6,940 KB
testcase_08 AC 38 ms
6,940 KB
testcase_09 AC 21 ms
6,940 KB
testcase_10 AC 26 ms
6,940 KB
testcase_11 AC 39 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
constexpr ll MAX = 2000000000000000000;
constexpr ld PI = 3.14159265358979;
constexpr ll MOD = 0;//2024948111;
ld dotorad(ld K){ return PI * K / 180.0; }
ld radtodo(ld K){ return K * 180.0 / PI; }
mt19937 mt;
void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); }
int main(){
    ll N,W,D;
    cin >> N >> W >> D;
    vector<ll> DP1(W + 1,-MAX),DP2(W + 1,-MAX);
    DP1[0] = 0;
    DP2[0] = 0;
    for(ll i = 0;i < N;i++){
        ll t,w,v;
        cin >> t >> w >> v;
        if(t == 1){
            for(ll j = W;j >= w;j--){
                DP1[j] = max(DP1[j],DP1[j - w] + v);
            }
        }
        else{
            for(ll j = W;j >= w;j--){
                DP2[j] = max(DP2[j],DP2[j - w] + v);
            }
        }
    }
    ll ans = 0;
    for(ll i = 0;i <= W;i++){
        for(ll j = 0;j <= W;j++){
            if(i + j <= W && abs(i - j) <= D){
                ans = max(ans,DP1[i] + DP2[j]);
            }
        }
    }
    cout << ans << endl;
}
0