結果

問題 No.2317 Expression Menu
ユーザー HIcoder
提出日時 2023-07-05 14:55:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 102,024 KB
最終ジャッジ日時 2025-02-15 06:15:05
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;


int main(){
    int N,X,Y;
    cin>>N>>X>>Y;

    vector<ll> A(N),B(N),C(N);
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i]>>C[i];
    }

    vector<vector<ll>> dp(X+1,vector<ll>(Y+1,-INF));

    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int x=X;x>=0;x--){
            for(int y=Y;y>=0;y--){
                if(x-A[i]>=0 && y-B[i]>=0 && dp[x-A[i]][y-B[i]]!=-INF){
                    dp[x][y]  = max(dp[x][y],dp[x-A[i]][y-B[i]]+C[i]);
                }
            }
        }
    }
    ll ans=-INF;
    for(int x=X;x>=0;x--){
        for(int y=Y;y>=0;y--){
            if(dp[x][y]!=-INF){
                ans=max(ans,dp[x][y]);
            }
        }
    }

    cout<<ans<<endl;


}
0