結果

問題 No.1037 exhausted
ユーザー ShibuyapShibuyap
提出日時 2020-04-25 08:45:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 195,496 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-04-24 07:26:58
合計ジャッジ時間 3,264 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 36 ms
34,688 KB
testcase_13 AC 35 ms
34,944 KB
testcase_14 AC 34 ms
34,688 KB
testcase_15 AC 36 ms
34,688 KB
testcase_16 AC 36 ms
34,688 KB
testcase_17 AC 36 ms
34,688 KB
testcase_18 AC 37 ms
34,816 KB
testcase_19 AC 35 ms
34,688 KB
testcase_20 AC 34 ms
34,688 KB
testcase_21 AC 32 ms
34,688 KB
testcase_22 AC 28 ms
34,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int main() {
    ll n, m, l;
    cin >> n >> m >> l;
    ll x[n+2] = {}, v[n+2] = {}, w[n+2] = {};
    x[n+1] = l;
    srep(i,1,n+1)cin >> x[i] >> v[i] >> w[i];
    ll dp[n+2][m+1];
    ll INF = 1001001001001001001;
    rep(i,n+2)rep(j,m+1)dp[i][j] = INF;
    dp[0][m] = 0;
    
    rep(i,n+1){
        int d = x[i+1] - x[i];
        rep(j,m+1){
            if(j < d)continue;
            dp[i+1][j-d] = min(dp[i+1][j-d], dp[i][j]);
            int nv = min(m, j-d+v[i+1]);
            dp[i+1][nv] = min(dp[i+1][nv], dp[i][j] + w[i+1]);
        }
    }

    ll ans = INF;
    rep(j,m+1)ans = min(ans, dp[n+1][j]);

    if(ans == INF)ans = -1;
    cout << ans << endl;
    return 0;
}
 
 
0