結果
| 問題 |
No.1037 exhausted
|
| コンテスト | |
| ユーザー |
IKyopro
|
| 提出日時 | 2020-04-24 22:21:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 990 bytes |
| コンパイル時間 | 2,215 ms |
| コンパイル使用メモリ | 200,104 KB |
| 最終ジャッジ日時 | 2025-01-10 00:00:08 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
void chmin(ll &a,ll b){if(a>b) a = b;}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,V,L;
cin >> N >> V >> L;
vec<int> x(N+2),v(N+2),w(N+2);
for(int i=1;i<=N;i++) cin >> x[i] >> v[i] >> w[i];
ll inf = 1e18;
x[N+1] = L;
vvec<ll> dp(N+2,vec<ll>(V+1,inf));
dp[0][V] = 0;
for(int i=1;i<=N+1;i++) for(int j=0;j<=V;j++){
int d = x[i]-x[i-1];
if(d<=j) chmin(dp[i][j-d],dp[i-1][j]);
if(i!=1){
int nj = min(V,j+v[i-1]);
if(d<=nj) chmin(dp[i][nj-d],dp[i-1][j]+w[i-1]);
}
}
ll ans = inf;
// for(int i=0;i<=N+1;i++) for(int j=0;j<=V;j++) cerr << dp[i][j] << (j!=V? " ":"\n");
for(int j=0;j<=V;j++) chmin(ans,dp[N+1][j]);
cout << (ans!=inf? ans:-1) << "\n";
}
IKyopro