結果

問題 No.844 split game
ユーザー ks2mks2m
提出日時 2019-06-28 22:55:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 79,712 KB
実行使用メモリ 71,204 KB
最終ジャッジ日時 2023-09-14 22:31:33
合計ジャッジ時間 18,293 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 284 ms
59,820 KB
testcase_01 AC 274 ms
59,612 KB
testcase_02 AC 451 ms
64,540 KB
testcase_03 AC 388 ms
64,320 KB
testcase_04 AC 253 ms
59,244 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 552 ms
70,220 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 566 ms
71,204 KB
testcase_19 AC 551 ms
68,688 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 121 ms
53,796 KB
testcase_27 WA -
testcase_28 AC 89 ms
51,844 KB
testcase_29 AC 138 ms
55,692 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 86 ms
52,844 KB
testcase_33 AC 151 ms
55,492 KB
testcase_34 AC 123 ms
54,992 KB
testcase_35 AC 159 ms
55,488 KB
testcase_36 AC 142 ms
55,792 KB
testcase_37 AC 176 ms
55,716 KB
testcase_38 AC 245 ms
57,880 KB
testcase_39 AC 371 ms
62,416 KB
testcase_40 AC 215 ms
58,804 KB
testcase_41 AC 45 ms
49,288 KB
testcase_42 AC 44 ms
49,384 KB
testcase_43 AC 45 ms
47,300 KB
testcase_44 AC 45 ms
49,316 KB
testcase_45 AC 44 ms
49,372 KB
testcase_46 AC 45 ms
49,372 KB
testcase_47 AC 45 ms
49,428 KB
testcase_48 WA -
testcase_49 AC 45 ms
49,472 KB
testcase_50 AC 46 ms
49,196 KB
testcase_51 AC 44 ms
49,204 KB
testcase_52 AC 45 ms
49,592 KB
testcase_53 AC 45 ms
49,436 KB
testcase_54 AC 44 ms
49,312 KB
testcase_55 AC 46 ms
49,552 KB
testcase_56 AC 46 ms
49,212 KB
testcase_57 AC 46 ms
49,512 KB
testcase_58 AC 44 ms
49,612 KB
testcase_59 AC 46 ms
49,280 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