結果
| 問題 | No.1037 exhausted |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-25 20:29:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 1,944 ms |
| コンパイル使用メモリ | 173,652 KB |
| 実行使用メモリ | 34,688 KB |
| 最終ジャッジ日時 | 2024-11-07 19:02:29 |
| 合計ジャッジ時間 | 3,249 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
const ll INF = 1e10;
const int MOD = 1000000007;
struct gas{
int x,v,w;
};
int main(){
int N,V,L;
cin >> N >> V >> L;
vector<gas> gass(N);
rep(i,N) cin >> gass[i].x >> gass[i].v >> gass[i].w;
vector<vector<ll>> dp(N+1,vector<ll>(V+1,INF));
dp[0][V] = 0;
for(int i=1;i<=N;i++){
ll d = (i==1 ? gass[i-1].x : gass[i-1].x - gass[i-2].x);
ll mn = INF;
rep(j,V+1){
if(d+V-gass[i-1].v <= j && V - gass[i-1].v >= 0) mn = min(mn,dp[i-1][j]);
if(j+d <= V) dp[i][j] = dp[i-1][j+d];
if(j-gass[i-1].v >= 0 && j+d-gass[i-1].v <= V) dp[i][j] = min(dp[i][j],dp[i-1][j+d-gass[i-1].v] + gass[i-1].w);
if(j==V) dp[i][j] = min(dp[i][j],mn + gass[i-1].w);
}
}
ll d = L - gass[N-1].x;
ll ans = INF;
for(ll i=d;i<=V;i++){
ans = min(ans,dp[N][i]);
}
cout << (ans==INF ? -1 : ans) << endl;
/*
rep(i,N+1){
rep(j,V+1) cout << dp[i][j] << " ";
cout << endl;
}*/
return 0;
}