結果
問題 | No.1037 exhausted |
ユーザー |
|
提出日時 | 2024-04-03 16:33:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,082 bytes |
コンパイル時間 | 745 ms |
コンパイル使用メモリ | 83,276 KB |
実行使用メモリ | 35,188 KB |
最終ジャッジ日時 | 2024-10-01 00:00:18 |
合計ジャッジ時間 | 1,782 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<ctime> #include<string> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<map> using namespace std; typedef long long LL; const int MR=2e3+10; int n,V,L; int x[MR],v[MR],w[MR]; LL dp[MR][MR]; //dp[i][j]是到加油站i且油量剩j时的最少花费 int main(){ cin>>n>>V>>L; for(int i=1;i<=n;i++){ cin>>x[i]>>v[i]>>w[i]; } x[n+1]=L; memset(dp,0x3f,sizeof(dp)); dp[0][V]=0; for(int i=0;i<=n;i++){ for(int j=0;j<=V;j++){ int t=x[i+1]-x[i]; //不加油直接出发,到下个站要消耗t if(j>=t) dp[i+1][j-t]=min(dp[i+1][j-t],dp[i][j]); //加油后出发,到下个站剩余 min(j+v[i],V)-t if(min(j+v[i],V)>=t){ dp[i+1][min(j+v[i],V)-t]=min(dp[i+1][min(j+v[i],V)-t],dp[i][j]+w[i]); } } } LL ans=1e18; for(int j=0;j<=V;j++) ans=min(ans,dp[n+1][j]); if(ans<1e18) cout<<ans<<endl; else cout<<-1<<endl; return 0; }