結果

問題 No.2701 A cans -> B cans
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-04-04 12:01:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 1,000 ms
コード長 1,168 bytes
コンパイル時間 2,928 ms
コンパイル使用メモリ 206,380 KB
実行使用メモリ 198,784 KB
最終ジャッジ日時 2024-04-04 12:01:42
合計ジャッジ時間 17,183 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 9 ms
6,676 KB
testcase_04 AC 8 ms
6,676 KB
testcase_05 AC 9 ms
6,676 KB
testcase_06 AC 8 ms
6,676 KB
testcase_07 AC 8 ms
6,676 KB
testcase_08 AC 8 ms
6,676 KB
testcase_09 AC 8 ms
6,676 KB
testcase_10 AC 9 ms
6,676 KB
testcase_11 AC 8 ms
6,676 KB
testcase_12 AC 8 ms
6,676 KB
testcase_13 AC 8 ms
6,676 KB
testcase_14 AC 8 ms
6,676 KB
testcase_15 AC 9 ms
6,676 KB
testcase_16 AC 8 ms
6,676 KB
testcase_17 AC 8 ms
6,676 KB
testcase_18 AC 8 ms
6,676 KB
testcase_19 AC 9 ms
6,676 KB
testcase_20 AC 8 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 247 ms
198,784 KB
testcase_24 AC 232 ms
198,784 KB
testcase_25 AC 244 ms
198,784 KB
testcase_26 AC 245 ms
198,784 KB
testcase_27 AC 259 ms
198,784 KB
testcase_28 AC 244 ms
198,784 KB
testcase_29 AC 259 ms
198,784 KB
testcase_30 AC 243 ms
198,784 KB
testcase_31 AC 243 ms
198,784 KB
testcase_32 AC 255 ms
198,784 KB
testcase_33 AC 244 ms
198,784 KB
testcase_34 AC 244 ms
198,784 KB
testcase_35 AC 253 ms
198,784 KB
testcase_36 AC 243 ms
198,784 KB
testcase_37 AC 262 ms
198,784 KB
testcase_38 AC 243 ms
198,784 KB
testcase_39 AC 244 ms
198,784 KB
testcase_40 AC 256 ms
198,784 KB
testcase_41 AC 242 ms
198,784 KB
testcase_42 AC 255 ms
198,784 KB
testcase_43 AC 243 ms
198,784 KB
testcase_44 AC 244 ms
198,784 KB
testcase_45 AC 255 ms
198,784 KB
testcase_46 AC 243 ms
198,784 KB
testcase_47 AC 244 ms
198,784 KB
testcase_48 AC 256 ms
198,784 KB
testcase_49 AC 244 ms
198,784 KB
testcase_50 AC 243 ms
198,784 KB
testcase_51 AC 256 ms
198,784 KB
testcase_52 AC 242 ms
198,784 KB
testcase_53 AC 266 ms
198,784 KB
testcase_54 AC 242 ms
198,784 KB
testcase_55 AC 244 ms
198,784 KB
testcase_56 AC 9 ms
6,676 KB
testcase_57 AC 8 ms
6,676 KB
testcase_58 AC 10 ms
6,676 KB
testcase_59 AC 9 ms
6,676 KB
testcase_60 AC 9 ms
6,676 KB
testcase_61 AC 8 ms
6,676 KB
testcase_62 AC 8 ms
6,676 KB
testcase_63 AC 9 ms
6,676 KB
testcase_64 AC 9 ms
6,676 KB
testcase_65 AC 9 ms
6,676 KB
testcase_66 AC 276 ms
198,784 KB
testcase_67 AC 288 ms
198,784 KB
testcase_68 AC 277 ms
198,784 KB
testcase_69 AC 276 ms
198,784 KB
testcase_70 AC 304 ms
198,784 KB
testcase_71 AC 275 ms
198,784 KB
testcase_72 AC 302 ms
198,784 KB
testcase_73 AC 275 ms
198,784 KB
testcase_74 AC 282 ms
198,784 KB
testcase_75 AC 299 ms
198,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    //店iでX回交換するのに必要な缶の数
    //(A-B)個補充すれば1回交換できる。(初めはA個)
    //A+(X-1)(A-B)個

    //dp(i, j)=i番目の店まででj個以下の缶で得られる嬉しさの最大値
    ll N, M, A, B, C;
    const ll inf = -1e18;
    cin >> N >> M;
    vector dp(N+1, vector<ll>(M+1, inf));
    dp[0][0] = 0;
    
    for (int i=1; i<=N; i++){
        cin >> A >> B >> C;
        //まずは1個買う
        for (int j=0; j<=M; j++){
            if (j-A>=0 && dp[i-1][j-A] != inf) dp[i][j] = max(dp[i][j], dp[i-1][j-A]+B*C);
        }
        //その後補充
        for (int j=0; j<=M; j++){
            if (j-(A-B)>=0 && dp[i][j-(A-B)] != inf) dp[i][j] = max(dp[i][j], dp[i][j-(A-B)]+B*C);
        }
        //または、i番目の店で1個も交換しない
        for (int j=0; j<=M; j++) dp[i][j] = max(dp[i][j], dp[i-1][j]);
    }

    ll mx = 0;
    for (int i=1; i<=M; i++){
        mx = max(mx, dp[N][i]);
        cout << mx << endl;
    }

    return 0;
}
0