結果
問題 | No.1037 exhausted |
ユーザー |
|
提出日時 | 2020-04-25 01:33:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,121 bytes |
コンパイル時間 | 1,995 ms |
コンパイル使用メモリ | 173,628 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-15 04:47:07 |
合計ジャッジ時間 | 3,072 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std::literals::string_literals;using i64 = std::int_fast64_t;using std::cout;using std::cerr;using std::endl;using std::cin;template<typename T>std::vector<T> make_v(size_t a){return std::vector<T>(a);}template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}int main() {int n, v, l; scanf("%d%d%d", &n, &v, &l);std::vector<int> x(n + 1), y(n + 1);std::vector<i64> z(n + 1);for(int i = 1; i <= n; i++) scanf("%d%d%lld", &x[i], &y[i], &z[i]);x.push_back(l);y.push_back(0);z.push_back(0);std::vector<i64> dp(v + 1, 0);for(int i = 1; i < (int)x.size(); i++) {std::vector<i64> to(v + 1, 1LL << 60);int diff = x[i] - x[i -1];for(int j = x[i] - x[i - 1]; j < v + 1; j++) {to[j - diff] = std::min(to[j - diff], dp[j]);if(j - diff + y[i] < v + 1) to[j - diff + y[i]] = std::min(to[j - diff + y[i]], dp[j] + z[i]);}dp.swap(to);}i64 ans = *std::min_element(begin(dp), end(dp));if(ans == 1LL << 60) ans = -1;printf("%lld\n", ans);return 0;}