結果

問題 No.2093 Shio Ramen
ユーザー nystnyst
提出日時 2022-10-07 21:48:31
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 107,592 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-06-12 06:57:49
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cmath>
#include <bitset>
#include <string>
using namespace std;

int main(){
    int n,I;cin >> n >> I;
    vector<int> s(n),a(n);
    for(int i=0;i<n;i++) cin >> s[i] >> a[i];
    vector dp(n+1,vector(I+1,-1));

    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=I;j++){
            if(dp[i][j]!=-1){
                dp[i+1][j] = max(dp[i+1][j],dp[i][j]);  
                if(j+s[i]<=I) dp[i+1][j+s[i]] = max(dp[i+1][j+s[i]],dp[i][j]+a[i]);
            }
        }
    }

    int ans = 0;
    for(int i=0;i<=I;i++) ans = max(ans,dp[n][i]);
    cout << ans << endl;
}
0