結果
問題 | No.1037 exhausted |
ユーザー |
![]() |
提出日時 | 2020-07-24 14:25:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 1,171 bytes |
コンパイル時間 | 2,193 ms |
コンパイル使用メモリ | 197,400 KB |
最終ジャッジ日時 | 2025-01-12 04:58:44 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>#define M_PI 3.14159265358979323846 // piusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef vector<ll> VI;typedef pair<ll, ll> P;typedef tuple<ll, ll, ll> t3;typedef tuple<ll, ll, ll, ll> t4;typedef tuple<ll, ll, ll, ll, ll> t5;#define rep(a,n) for(ll a = 0;a < n;a++)#define repi(a,b,n) for(ll a = b;a < n;a++)using namespace std;static const ll INF = 1e15;const ll mod = 1000000007;template<typename T>void chmin(T & ref, const T value) {if (ref > value) ref = value;}int main() {ll n, v, l;cin >> n >> v >> l;vector<ll> xs(n+1, 0), vs(n+1,0), ws(n+1,0);rep(i, n) {cin >> xs[i+1] >> vs[i+1] >> ws[i+1];}vector<vector<ll>> dp(n + 1, vector<ll>(v + 1, INF));dp[0][v] = 0;rep(i, n) {ll d = xs[i + 1] - xs[i];rep(j, v + 1) {if (j >= d) {chmin(dp[i + 1][j - d], dp[i][j]);auto nv = min(v, j - d + vs[i + 1]);chmin(dp[i + 1][nv], dp[i][j] + ws[i + 1]);}}}ll low = INF;for (int j = l - xs[n]; j < v + 1;j++) {chmin(low, dp[n][j]);}if (low == INF) {cout << -1 << endl;}else {cout << low << endl;}return 0;}