結果
問題 | No.1037 exhausted |
ユーザー |
|
提出日時 | 2020-04-26 12:49:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 5,288 ms |
コンパイル使用メモリ | 77,440 KB |
最終ジャッジ日時 | 2025-01-10 01:54:46 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using lint = long long; constexpr lint INF = 1LL << 60; void solve() { int n, m, l; std::cin >> n >> m >> l; std::vector<lint> dp(m + 1, 0); auto ndp = dp; int px = 0; while (n--) { int x, v, w; std::cin >> x >> v >> w; std::fill(ndp.begin(), ndp.end(), INF); for (int i = 0; i + (x - px) <= m; ++i) { ndp[i] = dp[i + (x - px)]; } for (int i = m; i >= 0; --i) { ndp[i] = std::min(ndp[i], ndp[std::max(i - v, 0)] + w); if (i + 1 <= m) ndp[i] = std::min(ndp[i], ndp[i + 1]); } std::swap(dp, ndp); px = x; } { int x = l; std::fill(ndp.begin(), ndp.end(), INF); for (int i = 0; i + (x - px) <= m; ++i) { ndp[i] = dp[i + (x - px)]; } std::swap(dp, ndp); } auto ans = *std::min_element(dp.begin(), dp.end()); std::cout << (ans == INF ? -1 : ans) << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }