結果
問題 | No.1037 exhausted |
ユーザー |
|
提出日時 | 2020-04-24 22:32:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 1,634 ms |
コンパイル使用メモリ | 172,432 KB |
実行使用メモリ | 35,072 KB |
最終ジャッジ日時 | 2024-10-15 03:12:25 |
合計ジャッジ時間 | 3,087 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long c[2010][2010]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); long long N, V, L; cin >> N >> V >> L; vector<long long> x(N), v(N), w(N); for (int i = 0; i < N; i++) cin >> x[i] >> v[i] >> w[i]; x.emplace_back(L); memset(c, 1000000007, sizeof(c)); long long inf = c[0][0]; if (V < x[0]) { cout << -1 << "\n"; return 0; } c[0][V-x[0]] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= V; j++) { int d = x[i+1] - x[i]; if (d <= j) { c[i+1][j-d] = min(c[i+1][j-d], c[i][j]); } int k = min(V, j+v[i]); if (d <= k) { c[i+1][k-d] = min(c[i+1][k-d], c[i][j]+w[i]); } } } long long ans = inf; for (int i = 0; i <= V; i++) { ans = min(ans, c[N][i]); } ans = ans == inf ? -1 : ans; cout << ans << "\n"; return 0; }