結果

問題 No.1037 exhausted
ユーザー nanophoto12nanophoto12
提出日時 2020-07-24 14:25:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,171 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 202,756 KB
実行使用メモリ 34,504 KB
最終ジャッジ日時 2023-09-07 08:15:20
合計ジャッジ時間 4,147 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 37 ms
34,480 KB
testcase_13 AC 36 ms
34,240 KB
testcase_14 AC 36 ms
34,120 KB
testcase_15 AC 35 ms
34,224 KB
testcase_16 AC 35 ms
34,116 KB
testcase_17 AC 36 ms
34,372 KB
testcase_18 AC 36 ms
34,232 KB
testcase_19 AC 36 ms
34,228 KB
testcase_20 AC 34 ms
34,212 KB
testcase_21 AC 32 ms
34,500 KB
testcase_22 AC 31 ms
34,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

template<typename T>
void chmin(T & ref, const T  value) {
	if (ref > value) ref = value;
}

int main() {
	ll n, v, l;
	cin >> n >> v >> l;
	vector<ll> xs(n+1, 0), vs(n+1,0), ws(n+1,0);
	rep(i, n) {
		cin >> xs[i+1] >> vs[i+1] >> ws[i+1];
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(v + 1, INF));
	dp[0][v] = 0;
	rep(i, n) {
		ll d = xs[i + 1] - xs[i];
		rep(j, v + 1) {
			if (j >= d) {
				chmin(dp[i + 1][j - d], dp[i][j]);
				auto nv = min(v, j - d + vs[i + 1]);
				chmin(dp[i + 1][nv], dp[i][j] + ws[i + 1]);
			}
		}
	}
	ll low = INF;
	for (int j = l - xs[n]; j < v + 1;j++)  {
		chmin(low, dp[n][j]);
	}
	if (low == INF) {
		cout << -1 << endl;
	}
	else {
		cout << low << endl;
	}
	return 0;
}
0