結果
| 問題 | 
                            No.1037 exhausted
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-01-05 17:01:54 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 27 ms / 2,000 ms | 
| コード長 | 946 bytes | 
| コンパイル時間 | 2,147 ms | 
| コンパイル使用メモリ | 198,236 KB | 
| 最終ジャッジ日時 | 2025-02-09 23:19:24 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, V, L;
    cin >> N >> V >> L;
    struct {
        int x;
        int v;
        int w;
    } a[N+2];
    for (int i = 1; i <= N; i++) {
        cin >> a[i].x >> a[i].v >> a[i].w;
    }
    a[0] = {0, 0, 0}; a[N+1] = {L, 0, 0};
    vector<vector<int>> dp(N+2, vector<int>(V+1, 1 << 30));
    dp[0][V] = 0;
    for (int i = 0; i < N+1; i++) {
        for (int j = 0; j <= V; j++) {
            if (dp[i][j] != 1 << 30 && a[i+1].x - a[i].x <= j) {
                dp[i+1][min(V, j-a[i+1].x+a[i].x+a[i+1].v)] =
                min(dp[i+1][min(V, j-a[i+1].x+a[i].x+a[i+1].v)], dp[i][j] + a[i+1].w);
                dp[i+1][j-a[i+1].x+a[i].x] =
                min(dp[i+1][j-a[i+1].x+a[i].x], dp[i][j]);
            }
        }
    }
    int ans = 1 << 30;
    for (int i = 0; i <= V; i++) ans = min(ans, dp[N+1][i]);
    if (ans == 1 << 30) ans = -1;
    cout << ans << endl;
}