結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー kyort0nkyort0n
提出日時 2019-12-18 23:18:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,477 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 172,232 KB
実行使用メモリ 199,008 KB
最終ジャッジ日時 2023-09-21 04:26:35
合計ジャッジ時間 9,066 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
198,768 KB
testcase_01 AC 57 ms
198,724 KB
testcase_02 AC 57 ms
198,792 KB
testcase_03 AC 57 ms
198,688 KB
testcase_04 AC 57 ms
198,740 KB
testcase_05 AC 57 ms
198,788 KB
testcase_06 AC 57 ms
198,888 KB
testcase_07 AC 57 ms
198,676 KB
testcase_08 AC 56 ms
198,768 KB
testcase_09 AC 58 ms
198,888 KB
testcase_10 AC 57 ms
198,748 KB
testcase_11 AC 58 ms
198,696 KB
testcase_12 AC 74 ms
198,708 KB
testcase_13 AC 117 ms
198,712 KB
testcase_14 AC 67 ms
198,800 KB
testcase_15 AC 66 ms
198,768 KB
testcase_16 AC 72 ms
198,860 KB
testcase_17 AC 75 ms
198,800 KB
testcase_18 AC 57 ms
198,732 KB
testcase_19 AC 56 ms
198,676 KB
testcase_20 AC 57 ms
198,756 KB
testcase_21 AC 58 ms
198,680 KB
testcase_22 AC 57 ms
198,748 KB
testcase_23 AC 58 ms
198,744 KB
testcase_24 AC 141 ms
198,720 KB
testcase_25 AC 141 ms
198,924 KB
testcase_26 AC 141 ms
198,920 KB
testcase_27 AC 140 ms
198,820 KB
testcase_28 AC 132 ms
198,780 KB
testcase_29 AC 132 ms
198,720 KB
testcase_30 AC 56 ms
198,960 KB
testcase_31 AC 57 ms
198,736 KB
testcase_32 AC 57 ms
198,904 KB
testcase_33 AC 57 ms
198,908 KB
testcase_34 AC 58 ms
198,904 KB
testcase_35 AC 148 ms
198,728 KB
testcase_36 AC 143 ms
198,808 KB
testcase_37 AC 144 ms
199,008 KB
testcase_38 AC 138 ms
198,784 KB
testcase_39 AC 136 ms
198,884 KB
testcase_40 AC 141 ms
198,832 KB
testcase_41 AC 138 ms
198,716 KB
testcase_42 AC 139 ms
198,884 KB
testcase_43 AC 140 ms
198,788 KB
testcase_44 AC 138 ms
198,804 KB
testcase_45 AC 138 ms
198,816 KB
testcase_46 AC 138 ms
198,828 KB
testcase_47 AC 136 ms
198,804 KB
testcase_48 AC 135 ms
198,836 KB
testcase_49 AC 134 ms
198,784 KB
testcase_50 AC 133 ms
198,812 KB
testcase_51 AC 133 ms
198,780 KB
testcase_52 AC 124 ms
198,784 KB
testcase_53 AC 140 ms
198,884 KB
testcase_54 AC 129 ms
198,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, K;
int dp[5001][5001][2];
vector<i_i> INPUT;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    INPUT.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> INPUT[i].first >> INPUT[i].second;
    }
    sort(INPUT.begin(), INPUT.end(), greater<i_i>());
    for(int i = 0; i <= 5000; i++) {
        for(int j = 0; j <= 5000; j++) {
            dp[i][j][1] = -1e9;
        }
    }
    for(int i = 0; i < N; i++) {
        int P = INPUT[i].first;
        int V = INPUT[i].second;
        for(int j = 0; j <= K; j++) {
            chmax(dp[i+1][j][0], dp[i][j][0]);
            chmax(dp[i+1][j][1], dp[i][j][1]);
            chmax(dp[i+1][j][0], dp[i][j][1] + V);
            if(j + P <= K) {
                chmax(dp[i+1][j+P][1], dp[i][j][0] + V);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= K; i++) {
        chmax(ans, dp[N][i][0]);
        chmax(ans, dp[N][i][1]);
    }
    cout << ans << endl;
    return 0;
}
0