結果
問題 |
No.1037 exhausted
|
ユーザー |
|
提出日時 | 2020-04-24 21:50:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 697 bytes |
コンパイル時間 | 2,318 ms |
コンパイル使用メモリ | 199,024 KB |
最終ジャッジ日時 | 2025-01-09 23:31:07 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; void chmin(int64_t& a, int64_t b){ a = min(a, b); } int main(){ int N, M, L; cin >> N >> M >> L; vector<int> 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; vector<vector<int64_t>> dp(N+2, vector<int64_t>(M+1, 1e18)); dp[0][M] = 0; for(int i=0; i<=N; i++){ for(int j=M; j>=0; j--) chmin(dp[i][min(M, j+V[i])], dp[i][j] + W[i]); int d = X[i+1] - X[i]; for(int j=d; j<=M; j++) chmin(dp[i+1][j-d], dp[i][j]); } int64_t ans = *min_element(dp[N+1].begin(), dp[N+1].end()); if(ans == 1e18) ans = -1; cout << ans << endl; return 0; }