結果
問題 | No.1037 exhausted |
ユーザー |
![]() |
提出日時 | 2020-04-24 22:11:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,065 bytes |
コンパイル時間 | 2,408 ms |
コンパイル使用メモリ | 202,116 KB |
最終ジャッジ日時 | 2025-01-09 23:55:36 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} using Int = long long; const char newl = '\n'; template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n,v,l; cin>>n>>v>>l; const Int MAX = 1e7; if(l>=MAX) drop(-1); // O(N+V+L) <- usoyanke uku vector<Int> xs(n),vs(n),ws(n); for(Int i=0;i<n;i++) cin>>xs[i]>>vs[i]>>ws[i]; const Int INF = 1e15; xs.emplace_back(l); vs.emplace_back(0); ws.emplace_back(INF); // keep dp[i]<=dp[i+1] deque<Int> dp(v+1,0); Int lst=0; for(Int i=0;i<=n;i++){ if(xs[i]-lst>v) drop(-1); for(Int j=0;j<xs[i]-lst;j++){ dp.pop_front(); dp.emplace_back(INF); } lst=xs[i]; for(Int j=v;j>=0;j--) chmin(dp[min(j+vs[i],v)],dp[j]+ws[i]); for(Int j=v;j>0;j--) chmin(dp[j-1],dp[j]); } cout<<dp[0]<<newl; return 0; }