結果
問題 | No.1037 exhausted |
ユーザー |
![]() |
提出日時 | 2020-04-24 22:40:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 1,193 bytes |
コンパイル時間 | 1,593 ms |
コンパイル使用メモリ | 172,116 KB |
実行使用メモリ | 34,560 KB |
最終ジャッジ日時 | 2024-10-15 03:15:14 |
合計ジャッジ時間 | 2,532 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;using lint = long long;const lint inf = 1LL << 60;const lint mod = 1000000007;template <class T>bool chmax(T &a, const T &b) {return (a < b) ? (a = b, 1) : 0;}template <class T>bool chmin(T &a, const T &b) {return (b < a) ? (a = b, 1) : 0;}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);lint n, V, L;cin >> n >> V >> L;vector<lint> 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;v[n + 1] = 0;w[n + 1] = 0;vector<vector<lint>> dp(n + 2, (vector<lint>(V + 1, inf)));dp[0][V] = 0;for (int i = 1; i <= n + 1; ++i) {for (int j = 0; j <= V; ++j) {if (j + (x[i] - x[i - 1]) <= V)chmin(dp[i][j], dp[i - 1][j + (x[i] - x[i - 1])]);}for (int j = V; j >= 0; --j) {chmin(dp[i][min(V, j + v[i])], dp[i][j] + w[i]);}}lint ret = inf;for (int j = 0; j <= V; ++j) {chmin(ret, dp[n + 1][j]);}if (ret == inf)cout << -1 << "\n";elsecout << ret << "\n";return 0;}