結果

問題 No.1037 exhausted
ユーザー t98slider
提出日時 2023-05-22 02:18:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 173,096 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-12-21 22:10:28
合計ジャッジ時間 2,604 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, V, L;
    cin >> n >> V >> L;
    vector<int> x(n + 2), v(n + 1), w(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> v[i] >> w[i];
    }
    x[n + 1] = L;
    vector<vector<ll>> dp(n + 2, vector<ll>(V + 1, 1ll << 60));
    dp[0][V] = 0;
    for(int i = 0; i <= n; i++){
        int d = x[i + 1] - x[i];
        for(int j = 0; j <= V; j++){
            int nj = min(V, j + v[i]);
            if(nj >= d) dp[i + 1][nj - d] = min(dp[i + 1][nj - d], dp[i][j] + w[i]);
            if(j >= d) dp[i + 1][j - d] = min(dp[i + 1][j - d], dp[i][j]);
        }
    }
    ll ans = *min_element(dp.back().begin(), dp.back().end());
    cout << (ans >> 60 ? -1 : ans) << '\n';
}
0