結果

問題 No.1037 exhausted
ユーザー ks2mks2m
提出日時 2020-04-24 23:15:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,382 bytes
コンパイル時間 2,682 ms
コンパイル使用メモリ 78,376 KB
実行使用メモリ 49,700 KB
最終ジャッジ日時 2024-04-23 04:15:00
合計ジャッジ時間 13,635 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,192 KB
testcase_01 AC 53 ms
37,276 KB
testcase_02 AC 56 ms
37,340 KB
testcase_03 AC 52 ms
37,276 KB
testcase_04 AC 55 ms
37,468 KB
testcase_05 AC 54 ms
37,104 KB
testcase_06 AC 53 ms
36,972 KB
testcase_07 WA -
testcase_08 AC 52 ms
37,360 KB
testcase_09 WA -
testcase_10 AC 54 ms
37,376 KB
testcase_11 WA -
testcase_12 AC 1,036 ms
49,164 KB
testcase_13 AC 1,060 ms
49,664 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1,183 ms
49,444 KB
testcase_17 AC 1,207 ms
49,516 KB
testcase_18 AC 1,215 ms
49,252 KB
testcase_19 WA -
testcase_20 AC 125 ms
40,664 KB
testcase_21 AC 121 ms
40,284 KB
testcase_22 AC 119 ms
40,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int l = Integer.parseInt(sa[2]);
		int[] x = new int[n];
		int[] v = new int[n];
		int[] w = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			x[i] = Integer.parseInt(sa[0]);
			v[i] = Integer.parseInt(sa[1]);
			w[i] = Integer.parseInt(sa[2]);
		}
		br.close();

		TreeMap<Integer, Long> map = new TreeMap<>();
		map.put(m, 0L);
		for (int i = 0; i < n; i++) {
			Map<Integer, Long> tm = map.tailMap(x[i]);
			if (tm.isEmpty()) {
				System.out.println(-1);
				return;
			}
			for (Integer o : tm.keySet().toArray(new Integer[0])) {
				int k = x[i] + Math.min(m, o - x[i] + v[i]);
				if (map.containsKey(k)) {
					map.put(k, Math.min(map.get(k), tm.get(o) + w[i]));
				} else {
					map.put(k, tm.get(o) + w[i]);
				}
			}
		}

		long ans = Long.MAX_VALUE;
		Map<Integer, Long> tm = map.tailMap(l);
		if (tm.isEmpty()) {
			System.out.println(-1);
			return;
		}
		for (long val : tm.values()) {
			ans = Math.min(ans, val);
		}
		System.out.println(ans);
	}
}
0