結果

問題 No.1037 exhausted
ユーザー betrue12betrue12
提出日時 2020-04-24 21:50:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 202,792 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-04-23 03:10:34
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 37 ms
34,688 KB
testcase_13 AC 38 ms
34,432 KB
testcase_14 AC 38 ms
34,432 KB
testcase_15 AC 39 ms
34,432 KB
testcase_16 AC 38 ms
34,304 KB
testcase_17 AC 37 ms
34,560 KB
testcase_18 AC 38 ms
34,560 KB
testcase_19 AC 38 ms
34,432 KB
testcase_20 AC 39 ms
34,432 KB
testcase_21 AC 38 ms
34,560 KB
testcase_22 AC 36 ms
34,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}

int main(){
    int N, M, L;
    cin >> N >> M >> L;
    vector<int> X(N+2), V(N+2), W(N+2);
    for(int i=1; i<=N; i++) cin >> X[i] >> V[i] >> W[i];
    X[N+1] = L;

    vector<vector<int64_t>> dp(N+2, vector<int64_t>(M+1, 1e18));
    dp[0][M] = 0;
    for(int i=0; i<=N; i++){
        for(int j=M; j>=0; j--) chmin(dp[i][min(M, j+V[i])], dp[i][j] + W[i]);
        int d = X[i+1] - X[i];
        for(int j=d; j<=M; j++) chmin(dp[i+1][j-d], dp[i][j]);
    }
    int64_t ans = *min_element(dp[N+1].begin(), dp[N+1].end());
    if(ans == 1e18) ans = -1;
    cout << ans << endl;
    return 0;
}
0