結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー tamarontamaron
提出日時 2019-12-19 18:17:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 734 bytes
コンパイル時間 1,662 ms
コンパイル使用メモリ 171,744 KB
実行使用メモリ 118,720 KB
最終ジャッジ日時 2023-09-21 07:10:05
合計ジャッジ時間 9,665 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const long long INF = 1e18;

void chmax(ll *a,ll b){
    if (*a<b) *a=b;
    return;
}

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> p(N),d(N);
    rep(i,N) cin>>p[i]>>d[i];
    vector<vector<vector<ll>>> dp(2,vector<vector<ll>>(N+1,vector<ll>(K+1,0)));
    rep(i,N)rep(j,K+1){
        chmax(&dp[0][i+1][j],dp[0][i][j]);
        if (j+d[i]<=K) chmax(&dp[1][i+1][j+p[i]],dp[0][i][j]+d[i]);
        if (dp[1][i][j]==0) continue;
        chmax(&dp[1][i+1][j],dp[1][i][j]);
        chmax(&dp[0][i+1][j],dp[1][i][j]+d[i]);
    }
    cout<<(dp[0][N][K]<dp[1][N][K] ? dp[1][N][K] : dp[0][N][K])<<endl;
    return 0;
}
0