結果
問題 | No.1037 exhausted |
ユーザー |
|
提出日時 | 2020-04-24 21:51:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 920 bytes |
コンパイル時間 | 2,659 ms |
コンパイル使用メモリ | 194,936 KB |
最終ジャッジ日時 | 2025-01-09 23:32:58 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;#define rep(i, n) for (int i = 0; i < (n); i++)#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)#define range(a) a.begin(), a.end()void chmin(ll &x, ll y) {x = min(x, y);}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);int N;ll V, L; cin >> N >> V >> L;vector<ll> X(N), v(N), W(N); rep(i, N) cin >> X[i] >> v[i] >> W[i];vector<ll> dp(V + 1, LLONG_MAX);if (V >= X[0]) {dp[V - X[0]] = 0;}rep(i, N) {repr(j, V + 1) if (dp[j] != LLONG_MAX) {chmin(dp[min(V, j + v[i])], dp[j] + W[i]);}ll d = (i + 1 < N ? X[i + 1] : L) - X[i];for (int j = 0; j <= V; j++) {dp[j] = j + d <= V ? dp[j + d] : LLONG_MAX;}}ll ans = *min_element(range(dp));if (ans == LLONG_MAX) ans = -1;cout << ans << endl;}