結果
| 問題 | 
                            No.1037 exhausted
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-04-25 14:30:58 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 38 ms / 2,000 ms | 
| コード長 | 1,067 bytes | 
| コンパイル時間 | 1,897 ms | 
| コンパイル使用メモリ | 173,296 KB | 
| 実行使用メモリ | 34,688 KB | 
| 最終ジャッジ日時 | 2024-11-07 01:40:33 | 
| 合計ジャッジ時間 | 2,908 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,v,l;cin >> n >> v >> l;
    vector<vector<ll>> dp(n+1,vector<ll>(v+1,INF));
    dp[0][v]=0;
    vector<ll> x(n+1),u(n),w(n);
    for(int i=0;i<n;i++){
        cin >> x[i+1] >> u[i] >> w[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=v;j++){
            if(dp[i][j]==INF){
                continue;
            }
            if(j>=x[i+1]-x[i]){
                chmin(dp[i+1][j-(x[i+1]-x[i])],dp[i][j]);
                chmin(dp[i+1][min(v,j-(x[i+1]-x[i])+u[i])],dp[i][j]+w[i]);
            }
        }
    }
    ll ans=INF;
    for(int i=l-x[n];i<=v;i++){
        chmin(ans,dp[n][i]);
    }
    cout <<(ans==INF?-1:ans) << endl;
}