結果
| 問題 | No.1037 exhausted |
| コンテスト | |
| ユーザー |
minato
|
| 提出日時 | 2020-05-23 01:43:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 1,643 bytes |
| コンパイル時間 | 4,027 ms |
| コンパイル使用メモリ | 238,980 KB |
| 最終ジャッジ日時 | 2025-01-10 15:11:56 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) {
cout << x << " ";
print(args...);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N,V,L; cin >> N >> V >> L;
vector<int> x(N+1),v(N+1),w(N+1);
rep(i,N) cin >> x[i] >> v[i] >> w[i];
x[N] = L;
vector<vector<ll>> dp(N+2, vector<ll>(V+1,1e18));
dp[0][V] = 0;
int cur = 0;
rep(i,N+1) {
int d = x[i] - cur;
rep(j,V+1) {
if (j < d or dp[i][j]==1e18) continue;
chmin(dp[i+1][j-d],dp[i][j]);
int nv = min(V,j-d+v[i]);
chmin(dp[i+1][nv],dp[i][j]+w[i]);
}
cur = x[i];
}
ll ans = 1e18;
rep(i,V+1) chmin(ans,dp[N+1][i]);
cout << (ans==1e18 ? -1 : ans) << ln;
}
minato