結果

問題 No.844 split game
ユーザー ks2mks2m
提出日時 2019-06-28 23:00:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,568 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 75,000 KB
実行使用メモリ 70,824 KB
最終ジャッジ日時 2023-09-14 22:33:07
合計ジャッジ時間 19,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
59,896 KB
testcase_01 AC 285 ms
60,300 KB
testcase_02 AC 472 ms
64,728 KB
testcase_03 AC 410 ms
64,188 KB
testcase_04 AC 272 ms
60,116 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 567 ms
70,616 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 584 ms
70,680 KB
testcase_19 AC 578 ms
69,316 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 119 ms
53,308 KB
testcase_27 WA -
testcase_28 AC 97 ms
52,092 KB
testcase_29 AC 141 ms
56,232 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 87 ms
52,676 KB
testcase_33 AC 150 ms
56,152 KB
testcase_34 AC 128 ms
56,028 KB
testcase_35 AC 150 ms
55,164 KB
testcase_36 AC 144 ms
55,680 KB
testcase_37 AC 170 ms
55,444 KB
testcase_38 AC 256 ms
57,588 KB
testcase_39 AC 398 ms
62,116 KB
testcase_40 AC 231 ms
58,448 KB
testcase_41 AC 46 ms
49,140 KB
testcase_42 AC 46 ms
49,332 KB
testcase_43 AC 46 ms
49,180 KB
testcase_44 AC 45 ms
49,336 KB
testcase_45 AC 46 ms
49,284 KB
testcase_46 AC 46 ms
49,392 KB
testcase_47 AC 47 ms
49,624 KB
testcase_48 WA -
testcase_49 AC 46 ms
49,328 KB
testcase_50 AC 47 ms
49,324 KB
testcase_51 AC 47 ms
49,324 KB
testcase_52 AC 46 ms
51,328 KB
testcase_53 AC 46 ms
49,256 KB
testcase_54 AC 46 ms
49,184 KB
testcase_55 AC 47 ms
49,704 KB
testcase_56 AC 46 ms
49,536 KB
testcase_57 AC 47 ms
49,404 KB
testcase_58 AC 46 ms
49,268 KB
testcase_59 AC 48 ms
49,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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 a = Integer.parseInt(sa[2]);
		Map<Integer, List<Area>> map = new HashMap<>();
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			Area area = new Area();
			area.l = Integer.parseInt(sa[0]);
			area.r = Integer.parseInt(sa[1]);
			area.p = Integer.parseInt(sa[2]);
			List<Area> list = map.get(area.r);
			if (list == null) {
				list = new ArrayList<>();
				map.put(area.r, list);
			}
			list.add(area);
		}
		br.close();

		long[] dp = new long[n + 1];
		long max = 0;
		for (int i = 1; i < n; i++) {
			List<Area> list = map.get(i);
			if (list == null) {
				dp[i] = max - a;
			} else {
				long max1 = Long.MIN_VALUE;
				for (Area area : list) {
					long val = dp[area.l - 1] + area.p;
					max1 = Math.max(max1, val);
				}
				dp[i] = max1 - a;
			}
			max = Math.max(max, dp[i]);
		}

		List<Area> list = map.get(n);
		if (list != null) {
			long max1 = Long.MIN_VALUE;
			for (Area area : list) {
				long val = dp[area.l - 1] + area.p;
				max1 = Math.max(max1, val);
			}
			dp[n] = max1;
			max = Math.max(max, dp[n]);
		}
		System.out.println(max);
	}

	static class Area {
		int l, r, p;
	}
}
0