結果

問題 No.844 split game
ユーザー ks2mks2m
提出日時 2019-06-28 23:34:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 576 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 3,819 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 70,716 KB
最終ジャッジ日時 2023-09-14 22:46:28
合計ジャッジ時間 19,361 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
60,012 KB
testcase_01 AC 289 ms
59,868 KB
testcase_02 AC 478 ms
63,768 KB
testcase_03 AC 397 ms
64,320 KB
testcase_04 AC 272 ms
59,168 KB
testcase_05 AC 518 ms
66,504 KB
testcase_06 AC 252 ms
58,580 KB
testcase_07 AC 245 ms
58,284 KB
testcase_08 AC 187 ms
56,148 KB
testcase_09 AC 385 ms
60,132 KB
testcase_10 AC 529 ms
66,284 KB
testcase_11 AC 539 ms
67,404 KB
testcase_12 AC 397 ms
60,820 KB
testcase_13 AC 285 ms
59,800 KB
testcase_14 AC 315 ms
61,496 KB
testcase_15 AC 572 ms
70,464 KB
testcase_16 AC 561 ms
70,020 KB
testcase_17 AC 571 ms
69,108 KB
testcase_18 AC 576 ms
70,140 KB
testcase_19 AC 568 ms
70,444 KB
testcase_20 AC 558 ms
69,492 KB
testcase_21 AC 553 ms
70,068 KB
testcase_22 AC 559 ms
70,716 KB
testcase_23 AC 134 ms
57,232 KB
testcase_24 AC 147 ms
56,300 KB
testcase_25 AC 137 ms
55,272 KB
testcase_26 AC 122 ms
53,384 KB
testcase_27 AC 147 ms
54,904 KB
testcase_28 AC 93 ms
51,304 KB
testcase_29 AC 151 ms
56,136 KB
testcase_30 AC 148 ms
56,332 KB
testcase_31 AC 149 ms
55,392 KB
testcase_32 AC 89 ms
51,956 KB
testcase_33 AC 150 ms
56,144 KB
testcase_34 AC 137 ms
55,228 KB
testcase_35 AC 159 ms
56,060 KB
testcase_36 AC 142 ms
55,728 KB
testcase_37 AC 178 ms
55,304 KB
testcase_38 AC 247 ms
58,048 KB
testcase_39 AC 388 ms
62,324 KB
testcase_40 AC 221 ms
57,796 KB
testcase_41 AC 46 ms
49,120 KB
testcase_42 AC 46 ms
49,144 KB
testcase_43 AC 46 ms
49,232 KB
testcase_44 AC 45 ms
49,236 KB
testcase_45 AC 45 ms
49,520 KB
testcase_46 AC 45 ms
49,340 KB
testcase_47 AC 45 ms
49,464 KB
testcase_48 AC 45 ms
49,288 KB
testcase_49 AC 46 ms
49,480 KB
testcase_50 AC 45 ms
49,044 KB
testcase_51 AC 46 ms
49,532 KB
testcase_52 AC 45 ms
49,120 KB
testcase_53 AC 46 ms
49,004 KB
testcase_54 AC 46 ms
49,052 KB
testcase_55 AC 47 ms
49,308 KB
testcase_56 AC 45 ms
49,412 KB
testcase_57 AC 47 ms
49,436 KB
testcase_58 AC 46 ms
49,124 KB
testcase_59 AC 47 ms
49,216 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);
			dp[i] = max - a;
			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[i] = Math.max(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