結果

問題 No.1037 exhausted
ユーザー QCFium
提出日時 2020-04-24 22:09:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 167,736 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-15 02:57:36
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int max = ri();
	int l = ri();
	struct Station {
		int pos;
		int max;
		int cost;
	};
	Station stations[n];
	for (auto &i : stations) i.pos = ri(), i.max = ri(), i.cost = ri();
	int64_t dp[max + 1];
	for (auto &i : dp) i = 1000000000000000000;
	dp[max] = 0;
	int last = 0;
	for (int i = 0; i < n; i++) {
		int move = stations[i].pos - last;
		last = stations[i].pos;
		for (int j = 0; j < move && j <= max; j++) dp[j] = 1000000000000000000;
		if (move) for (int j = move; j <= max; j++) dp[j - move] = dp[j], dp[j] = 1000000000000000000;
		for (int j = max; j >= 0; j--) {
			auto &target = dp[std::min(j + stations[i].max, max)];
			target = std::min(target, dp[j] + stations[i].cost);
		}
	}
	int64_t res = 1000000000000000000;
	for (int i = l - last; i <= max; i++) res = std::min(res, dp[i]);
	printf("%" PRId64 "\n", res == 1000000000000000000 ? -1 : res);
	return 0;
}
0