結果

問題 No.2741 Balanced Choice
ユーザー mealymealy
提出日時 2024-04-21 13:57:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 2,111 bytes
コンパイル時間 5,937 ms
コンパイル使用メモリ 336,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 13:57:34
合計ジャッジ時間 6,854 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using mint = atcoder::modint998244353;
//using mint = atcoder::modint1000000007;
using namespace atcoder;
using namespace std;

using ll = long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vm = vector<mint>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vpi = vector<pair<int,int>>;
using vpl = vector<pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < n; i++)
#define replr(i,l,r) for (ll i = l; i < r; i++)
set<char> abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
const int inf =1e9;
const ll infl = 4e18;

template <typename T>
bool chmax(T &a, const T& b) {if (a < b) {a = b;  return true;}return false;}
template <typename T>
bool chmin(T &a, const T& b) {if (a > b) {a = b;  return true;}return false;}
template <typename T>
T max(vector<T> &v) {T m = 0;for (auto x : v) chmax(m, x);return m;}
template <typename T>
T min(vector<T> &v) {T m = inf;for (auto x : v) chmin(m, x);return m;}
template <typename T>
void print(vector<T> &v){for(auto x : v){cout<<x<<' ';}cout<<'\n';}
/*memo

*/


int main(){
    int N,W,D; cin >> N >> W >> D;
    vpi wv0, wv1;
    rep(i,N){
        int t,w,v; cin >> t >> w >> v;
        if(t == 0) wv0.push_back({w,v});
        else wv1.push_back({w,v});
    }
    vi dp0(W+1,-1), dp1(W+1,-1);
    dp0[0] = 0;
    dp1[0] = 0;
    rep(i,wv0.size()){
        for(int j = W; j >= wv0[i].first; j--){
            if (dp0[j-wv0[i].first] == -1) continue;
            chmax(dp0[j], dp0[j-wv0[i].first] + wv0[i].second);
        }
    }
    rep(i,wv1.size()){
        for(int j = W; j >= wv1[i].first; j--){
            if (dp1[j-wv1[i].first] == -1) continue;
            chmax(dp1[j], dp1[j-wv1[i].first] + wv1[i].second);
        }
    }
    int ans=0;
    rep(i,W+1){
        replr(j,-D,D+1){
            if(i+j < 0 || i+j > W || 2*i+j > W) continue;
            if (dp0[i] == -1 || dp1[i+j] == -1) continue;
            chmax(ans, dp0[i] + dp1[i+j]);
        }
    }
    cout << ans << endl;
}
0