結果
問題 | No.1037 exhausted |
ユーザー |
![]() |
提出日時 | 2024-02-29 19:49:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 822 bytes |
コンパイル時間 | 2,115 ms |
コンパイル使用メモリ | 199,284 KB |
最終ジャッジ日時 | 2025-02-19 22:03:25 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);ll N, V, L, d;cin >> N >> V >> L;vector<ll> x(N+1), v(N+1), w(N+1);for (int i = 1; i <= N; i++) cin >> x[i] >> v[i] >> w[i];vector<vector<ll>> dp(N+1, vector<ll>(V+1, 1e18));dp[0][V] = 0;for (int i=0; i<N; i++){d = x[i+1] - x[i];for (int j=0; j<=V; j++){if (j-d < 0) continue;dp[i+1][j-d] = min(dp[i+1][j-d], dp[i][j]);dp[i+1][min(j-d+v[i+1], V)] = min(dp[i+1][min(j-d+v[i+1], V)], dp[i][j]+w[i+1]);}}ll ans = 1e18;for (ll i=L-x[N]; i<=V; i++) ans = min(ans, dp[N][i]);if (ans == 1e18) cout << -1 << endl;else cout << ans << endl;return 0;}