結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー koyoprokoyopro
提出日時 2019-12-30 18:25:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 1,817 bytes
コンパイル時間 1,464 ms
コンパイル使用メモリ 164,972 KB
実行使用メモリ 394,240 KB
最終ジャッジ日時 2024-04-26 16:50:23
合計ジャッジ時間 16,026 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 11 ms
12,288 KB
testcase_10 AC 7 ms
8,320 KB
testcase_11 AC 7 ms
8,576 KB
testcase_12 AC 93 ms
80,128 KB
testcase_13 AC 359 ms
275,840 KB
testcase_14 AC 55 ms
47,616 KB
testcase_15 AC 56 ms
51,072 KB
testcase_16 AC 86 ms
74,752 KB
testcase_17 AC 105 ms
91,520 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 7 ms
8,320 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 4 ms
6,272 KB
testcase_24 AC 494 ms
394,112 KB
testcase_25 AC 474 ms
394,112 KB
testcase_26 AC 462 ms
394,112 KB
testcase_27 AC 461 ms
394,112 KB
testcase_28 AC 450 ms
394,112 KB
testcase_29 AC 449 ms
394,112 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 4 ms
5,504 KB
testcase_33 AC 5 ms
6,784 KB
testcase_34 AC 10 ms
10,880 KB
testcase_35 AC 482 ms
394,112 KB
testcase_36 AC 475 ms
394,112 KB
testcase_37 AC 473 ms
394,112 KB
testcase_38 AC 466 ms
394,112 KB
testcase_39 AC 468 ms
394,240 KB
testcase_40 AC 460 ms
394,112 KB
testcase_41 AC 458 ms
394,240 KB
testcase_42 AC 461 ms
394,112 KB
testcase_43 AC 461 ms
394,240 KB
testcase_44 AC 461 ms
394,112 KB
testcase_45 AC 463 ms
394,112 KB
testcase_46 AC 452 ms
394,240 KB
testcase_47 AC 449 ms
394,240 KB
testcase_48 AC 451 ms
394,112 KB
testcase_49 AC 450 ms
394,240 KB
testcase_50 AC 450 ms
394,240 KB
testcase_51 AC 456 ms
394,112 KB
testcase_52 AC 370 ms
317,568 KB
testcase_53 AC 455 ms
394,240 KB
testcase_54 AC 418 ms
394,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
#define MAX LONG_LONG_MAX

int dxy[] = {0, 1, 0, -1, 0};

/*================================*/

int N, K;
struct P {
    int score;
    int price;
};

signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin >> N >> K;
    vector<P> LIST(N);
    REP(i, N) {
        cin >> LIST[i].price >> LIST[i].score;
    }
    sort(ALL(LIST), [](const P a, const P b) {return a.price > b.price || (a.price == b.price && a.score > b.score); });
    
    int DP[N][K+1][2];
    REP(i, N) REP(j, K+1) REP(k, 2) DP[i][j][k] = -1;
    DP[0][K][0] = 0;
    P p = LIST[0];
    if (K >= p.price) {
        DP[0][K - p.price][1] = p.score;
    }
    
    FOR(i, 1, N) REP(j, K+1) REP(k, 2) {
        P p = LIST[i];
        if (DP[i-1][j][k] > -1) {
            if (j >= p.price) DP[i][j - p.price][1] = max(DP[i][j - p.price][1], DP[i-1][j][k] + p.score); // 買った場合
            if (k == 1) DP[i][j][0] = max(DP[i][j][0], DP[i-1][j][k] + p.score); // 特典を利用した場合
            DP[i][j][k] = max(DP[i][j][k], DP[i-1][j][k]); // 買わなかった場合
        }
    }
    int ans = 0;
    REP(i, N) REP(j, K+1) REP(k, 2) {
        ans = max(ans, DP[i][j][k]);
    }
    
    cout << ans << endl;
    
    return 0;
}
0