結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー milanis48663220milanis48663220
提出日時 2020-04-14 01:46:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 88,252 KB
実行使用メモリ 199,160 KB
最終ジャッジ日時 2024-04-08 15:25:24
合計ジャッジ時間 6,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 3 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 7 ms
18,164 KB
testcase_10 AC 5 ms
9,996 KB
testcase_11 AC 6 ms
18,076 KB
testcase_12 AC 30 ms
49,216 KB
testcase_13 AC 100 ms
186,400 KB
testcase_14 AC 18 ms
30,752 KB
testcase_15 AC 20 ms
40,876 KB
testcase_16 AC 31 ms
79,708 KB
testcase_17 AC 54 ms
179,964 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 4 ms
8,084 KB
testcase_22 AC 3 ms
7,848 KB
testcase_23 AC 4 ms
7,940 KB
testcase_24 AC 125 ms
199,160 KB
testcase_25 AC 121 ms
199,160 KB
testcase_26 AC 120 ms
199,160 KB
testcase_27 AC 161 ms
199,160 KB
testcase_28 AC 113 ms
199,160 KB
testcase_29 AC 113 ms
199,160 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 4 ms
7,880 KB
testcase_33 AC 4 ms
7,976 KB
testcase_34 AC 5 ms
8,252 KB
testcase_35 AC 121 ms
199,160 KB
testcase_36 AC 122 ms
199,160 KB
testcase_37 AC 122 ms
199,160 KB
testcase_38 AC 121 ms
199,160 KB
testcase_39 AC 122 ms
199,160 KB
testcase_40 AC 120 ms
199,160 KB
testcase_41 AC 121 ms
199,160 KB
testcase_42 AC 120 ms
199,160 KB
testcase_43 AC 121 ms
199,160 KB
testcase_44 AC 120 ms
199,160 KB
testcase_45 AC 119 ms
199,160 KB
testcase_46 AC 112 ms
199,160 KB
testcase_47 AC 113 ms
199,160 KB
testcase_48 AC 111 ms
199,160 KB
testcase_49 AC 112 ms
199,160 KB
testcase_50 AC 111 ms
199,160 KB
testcase_51 AC 111 ms
199,160 KB
testcase_52 AC 106 ms
198,972 KB
testcase_53 AC 122 ms
199,160 KB
testcase_54 AC 105 ms
199,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P_;

int dp[5005][5005][2];
int P[5000], D[5000];
P_ p[5000];
int N, K;
const int INF = 1e9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> P[i] >> D[i];
        p[i] = P_(P[i], D[i]);
    }
    sort(p, p+N, greater<P_>());
    for(int i = 0; i < N; i++){
        P[i] = p[i].first;
        D[i] = p[i].second;
    }

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= K; j++){
            dp[i][j][0] = -INF;
            dp[i][j][1] = -INF;
        }
    }
    dp[0][0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= K; j++){
            dp[i+1][j][0] = max({dp[i+1][j][0], dp[i][j][0], dp[i][j][1]+D[i]});
            dp[i+1][j][1] = max(dp[i][j][1], dp[i+1][j][1]);
            if(j+P[i] <= K) dp[i+1][j+P[i]][1] = max({dp[i+1][j+P[i]][1], dp[i][j+P[i]][1], dp[i][j][0]+D[i]});
        }
    } 
    int ans = 0;
    for(int i = 0; i <= K; i++){
        ans = max(ans, dp[N][i][0]);
        ans = max(ans, dp[N][i][1]);
    }
    cout << ans << endl;
}
0