結果

問題 No.1037 exhausted
ユーザー ks2mks2m
提出日時 2020-04-24 23:11:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,443 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 80,164 KB
実行使用メモリ 49,728 KB
最終ジャッジ日時 2024-04-23 04:11:51
合計ジャッジ時間 11,957 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
37,364 KB
testcase_01 AC 49 ms
37,336 KB
testcase_02 AC 49 ms
37,548 KB
testcase_03 AC 48 ms
36,972 KB
testcase_04 AC 49 ms
37,224 KB
testcase_05 AC 47 ms
37,148 KB
testcase_06 AC 49 ms
37,404 KB
testcase_07 WA -
testcase_08 AC 49 ms
37,156 KB
testcase_09 WA -
testcase_10 AC 48 ms
37,252 KB
testcase_11 WA -
testcase_12 AC 883 ms
49,616 KB
testcase_13 AC 909 ms
49,484 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1,048 ms
49,348 KB
testcase_17 AC 1,046 ms
49,604 KB
testcase_18 AC 1,078 ms
49,452 KB
testcase_19 WA -
testcase_20 AC 113 ms
40,508 KB
testcase_21 AC 107 ms
40,552 KB
testcase_22 AC 92 ms
40,236 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();

		if ((n + 1) * m < l) {
			System.out.println(-1);
			return;
		}

		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 = Math.min(x[i] + m, o + 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