結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー 👑 hitonanodehitonanode
提出日時 2019-12-14 00:14:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 179,896 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 07:37:53
合計ジャッジ時間 7,566 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 25 ms
4,376 KB
testcase_13 AC 82 ms
4,380 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 20 ms
4,384 KB
testcase_16 AC 31 ms
4,376 KB
testcase_17 AC 25 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,384 KB
testcase_24 AC 109 ms
4,380 KB
testcase_25 AC 117 ms
4,376 KB
testcase_26 AC 115 ms
4,376 KB
testcase_27 AC 115 ms
4,376 KB
testcase_28 AC 161 ms
4,380 KB
testcase_29 AC 159 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 116 ms
4,380 KB
testcase_36 AC 115 ms
4,380 KB
testcase_37 AC 119 ms
4,376 KB
testcase_38 AC 119 ms
4,376 KB
testcase_39 AC 120 ms
4,376 KB
testcase_40 AC 111 ms
4,380 KB
testcase_41 AC 112 ms
4,376 KB
testcase_42 AC 113 ms
4,380 KB
testcase_43 AC 114 ms
4,376 KB
testcase_44 AC 115 ms
4,376 KB
testcase_45 AC 115 ms
4,376 KB
testcase_46 AC 155 ms
4,380 KB
testcase_47 AC 161 ms
4,380 KB
testcase_48 AC 164 ms
4,376 KB
testcase_49 AC 159 ms
4,376 KB
testcase_50 AC 158 ms
4,376 KB
testcase_51 AC 161 ms
4,376 KB
testcase_52 AC 83 ms
4,380 KB
testcase_53 AC 102 ms
4,380 KB
testcase_54 AC 88 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }


int main()
{
    int N, K;
    cin >> N >> K;
    vector<pint> PD(N);
    REP(i, N) cin >> PD[i].first >> PD[i].second;
    sort(PD.rbegin(), PD.rend());

    vector<vector<int>> dp(2, vector<int>(K + 1));
    REP(j, K + 1) REP(k, 2) dp[k][j] = -1e9;
    dp[0][K] = 0;

    for (auto p : PD)
    {
        vector<vector<int>> dpnew = dp;
        REP(d, 2) REP(j, K + 1)
        {
            if (dp[d][j] >= 0)
            {
                if (j - p.first >= 0) mmax(dpnew[1][j - p.first], dp[d][j] + p.second);
            }
        }
        REP(j, K + 1) if (dp[1][j] >= 0) mmax(dpnew[0][j], dp[1][j] + p.second);
        dp = dpnew;
    }
    int ret = 0;
    REP(k, 2) REP(j, K + 1) mmax(ret, dp[k][j]);
    cout << ret << endl;
}
0