結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー ace_amuroace_amuro
提出日時 2022-06-30 12:30:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 81,080 KB
実行使用メモリ 199,216 KB
最終ジャッジ日時 2023-08-15 22:34:55
合計ジャッジ時間 7,378 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 6 ms
16,756 KB
testcase_10 AC 4 ms
10,512 KB
testcase_11 AC 5 ms
16,256 KB
testcase_12 AC 24 ms
48,384 KB
testcase_13 AC 96 ms
179,664 KB
testcase_14 AC 15 ms
29,928 KB
testcase_15 AC 17 ms
41,804 KB
testcase_16 AC 33 ms
78,292 KB
testcase_17 AC 75 ms
159,524 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 4 ms
6,888 KB
testcase_22 AC 2 ms
6,196 KB
testcase_23 AC 3 ms
6,372 KB
testcase_24 AC 110 ms
198,944 KB
testcase_25 AC 112 ms
198,992 KB
testcase_26 AC 128 ms
199,216 KB
testcase_27 AC 126 ms
198,936 KB
testcase_28 AC 137 ms
199,068 KB
testcase_29 AC 139 ms
199,068 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,388 KB
testcase_32 AC 3 ms
6,232 KB
testcase_33 AC 3 ms
6,572 KB
testcase_34 AC 4 ms
7,452 KB
testcase_35 AC 109 ms
198,936 KB
testcase_36 AC 110 ms
198,952 KB
testcase_37 AC 115 ms
198,944 KB
testcase_38 AC 112 ms
199,004 KB
testcase_39 AC 112 ms
198,944 KB
testcase_40 AC 128 ms
198,948 KB
testcase_41 AC 127 ms
198,936 KB
testcase_42 AC 128 ms
199,020 KB
testcase_43 AC 128 ms
198,948 KB
testcase_44 AC 127 ms
199,064 KB
testcase_45 AC 127 ms
199,132 KB
testcase_46 AC 139 ms
199,016 KB
testcase_47 AC 139 ms
198,944 KB
testcase_48 AC 138 ms
198,952 KB
testcase_49 AC 138 ms
199,000 KB
testcase_50 AC 138 ms
198,956 KB
testcase_51 AC 138 ms
198,952 KB
testcase_52 AC 99 ms
194,388 KB
testcase_53 AC 106 ms
198,936 KB
testcase_54 AC 88 ms
199,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<ctime>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
const int MR=5000+5;
int n,K,p[MR],d[MR];
int dp[MR][MR][2];

int main(){
    cin>>n>>K;
    for(int i=1;i<=n;i++) cin>>p[i]>>d[i];
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(p[i]<p[j]){
                swap(p[i],p[j]);
                swap(d[i],d[j]);
            }
        }
    }
    for(int j=0;j<=K;j++) dp[0][j][1]=-1e9;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=K;j++){
            dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j][1]+d[i]);
            dp[i][j][1]=dp[i-1][j][1];
            if(j>=p[i]) dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j-p[i]][0]+d[i]);
        }
    }
    int ans=max(dp[n][K][0],dp[n][K][1]);
    cout<<ans<<endl;
    return 0;
}
0