結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 6 ms
16,556 KB
testcase_10 AC 4 ms
10,500 KB
testcase_11 AC 5 ms
16,372 KB
testcase_12 AC 23 ms
48,464 KB
testcase_13 AC 89 ms
185,376 KB
testcase_14 AC 15 ms
29,872 KB
testcase_15 AC 17 ms
41,932 KB
testcase_16 AC 33 ms
78,288 KB
testcase_17 AC 74 ms
178,192 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 4 ms
6,888 KB
testcase_22 AC 2 ms
6,060 KB
testcase_23 AC 3 ms
6,364 KB
testcase_24 AC 105 ms
198,940 KB
testcase_25 AC 108 ms
198,988 KB
testcase_26 AC 117 ms
198,940 KB
testcase_27 AC 123 ms
199,060 KB
testcase_28 AC 128 ms
198,984 KB
testcase_29 AC 130 ms
198,956 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 2 ms
6,224 KB
testcase_33 AC 3 ms
6,572 KB
testcase_34 AC 4 ms
7,448 KB
testcase_35 AC 103 ms
199,024 KB
testcase_36 AC 102 ms
198,944 KB
testcase_37 AC 106 ms
199,136 KB
testcase_38 AC 105 ms
199,136 KB
testcase_39 AC 105 ms
199,172 KB
testcase_40 AC 122 ms
198,936 KB
testcase_41 AC 118 ms
199,000 KB
testcase_42 AC 118 ms
198,996 KB
testcase_43 AC 118 ms
199,076 KB
testcase_44 AC 118 ms
198,932 KB
testcase_45 AC 118 ms
199,132 KB
testcase_46 AC 130 ms
198,996 KB
testcase_47 AC 129 ms
199,132 KB
testcase_48 AC 127 ms
198,948 KB
testcase_49 AC 129 ms
198,944 KB
testcase_50 AC 130 ms
198,948 KB
testcase_51 AC 132 ms
198,936 KB
testcase_52 AC 96 ms
198,708 KB
testcase_53 AC 106 ms
198,936 KB
testcase_54 AC 86 ms
198,940 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