結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー TAISA_TAISA_
提出日時 2019-12-15 00:16:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,263 bytes
コンパイル時間 1,815 ms
コンパイル使用メモリ 178,236 KB
実行使用メモリ 812,988 KB
最終ジャッジ日時 2023-09-10 13:01:43
合計ジャッジ時間 6,168 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 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,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 53 ms
34,568 KB
testcase_10 AC 30 ms
20,872 KB
testcase_11 AC 31 ms
21,740 KB
testcase_12 AC 478 ms
272,384 KB
testcase_13 MLE -
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>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<P> v;
    for (int i = 0; i < n; i++) {
        int p, d;
        cin >> p >> d;
        v.push_back(P(p, d));
    }
    sort(all(v));
    vector<vector<vector<int>>> dp(
        n + 1, vector<vector<int>>(k + 1, vector<int>(2, -INF)));
    dp[n][0][0] = 0;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j <= k; j++) {
            chmax(dp[i][j][0], dp[i + 1][j][0]);
            chmax(dp[i][j][1], dp[i + 1][j][1]);
            chmax(dp[i][j][0], dp[i + 1][j][1] + v[i].second);
            if (j >= v[i].first) {
                chmax(dp[i][j][1], dp[i + 1][j - v[i].first][0] + v[i].second);
            }
        }
    }
    int res = 0;
    for (int i = 0; i <= k; i++) {
        chmax(res, dp[0][i][0]);
        chmax(res, dp[0][i][1]);
    }
    cout << res << endl;
}
0