結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー 37zigen37zigen
提出日時 2016-11-17 17:07:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,057 ms / 2,000 ms
コード長 1,864 bytes
コンパイル時間 3,416 ms
コンパイル使用メモリ 75,544 KB
実行使用メモリ 67,348 KB
最終ジャッジ日時 2023-09-02 12:48:12
合計ジャッジ時間 28,869 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,736 KB
testcase_01 AC 121 ms
55,468 KB
testcase_02 AC 120 ms
55,820 KB
testcase_03 AC 121 ms
55,672 KB
testcase_04 AC 169 ms
56,112 KB
testcase_05 AC 179 ms
56,116 KB
testcase_06 AC 196 ms
58,400 KB
testcase_07 AC 166 ms
55,812 KB
testcase_08 AC 175 ms
54,480 KB
testcase_09 AC 186 ms
56,076 KB
testcase_10 AC 172 ms
55,932 KB
testcase_11 AC 183 ms
56,020 KB
testcase_12 AC 178 ms
56,528 KB
testcase_13 AC 490 ms
60,568 KB
testcase_14 AC 482 ms
60,424 KB
testcase_15 AC 698 ms
64,780 KB
testcase_16 AC 874 ms
65,496 KB
testcase_17 AC 870 ms
65,124 KB
testcase_18 AC 434 ms
60,356 KB
testcase_19 AC 1,018 ms
66,892 KB
testcase_20 AC 621 ms
62,612 KB
testcase_21 AC 971 ms
66,964 KB
testcase_22 AC 631 ms
62,888 KB
testcase_23 AC 961 ms
66,552 KB
testcase_24 AC 566 ms
60,368 KB
testcase_25 AC 1,039 ms
66,784 KB
testcase_26 AC 434 ms
60,192 KB
testcase_27 AC 879 ms
65,200 KB
testcase_28 AC 834 ms
66,832 KB
testcase_29 AC 634 ms
64,928 KB
testcase_30 AC 981 ms
66,468 KB
testcase_31 AC 471 ms
60,928 KB
testcase_32 AC 505 ms
60,644 KB
testcase_33 AC 997 ms
67,348 KB
testcase_34 AC 1,000 ms
66,844 KB
testcase_35 AC 1,057 ms
67,220 KB
testcase_36 AC 1,001 ms
66,824 KB
testcase_37 AC 998 ms
67,332 KB
testcase_38 AC 959 ms
66,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q448 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] T = new int[N];
		int[] D = new int[N];
		int max = -1;
		for (int i = 0; i < N; ++i) {
			T[i] = sc.nextInt();
			D[i] = sc.nextInt();
			max = Math.max(max, D[i]);
		}

		int left = -1;
		int right = max;

		outer: while (right - left > 1) {
			int middle = (left + right) / 2;

			int preTime = -K;
			for (int i = 0; i < N; ++i) {
				if (D[i] > middle) {
					if (T[i] - preTime < K) {
						left = middle;
						continue outer;
					} else
						preTime = T[i];
				}
			}

			right = middle;
		}

		max = right;
		System.out.println(max);

		int[] count = new int[N];
		int preTime = -K;
		for (int i = 0; i < N; ++i) {
			if (D[i] > max) {
				preTime = T[i];
			} else {
				if (preTime + K <= T[i]) {
					++count[i];
				}
			}
		}
		preTime = T[N - 1] + K;
		for (int i = N - 1; i >= 0; --i) {
			if (D[i] > max) {
				preTime = T[i];
			} else {
				if (preTime >= T[i] + K) {
					++count[i];
				}
			}
		}

		int[] pendingIndex = new int[N];
		int pos = 0;
		for (int i = 0; i < N; ++i) {
			if (count[i] == 2) {
				pendingIndex[pos++] = i;
			}
		}

		pendingIndex = Arrays.copyOf(pendingIndex, pos);


		long[] dp = new long[pos];
		int pre = -1;
		for (int i = 0; i < pos; ++i) {
			while (pre + 1 < pos && T[pendingIndex[i]] >= T[pendingIndex[pre + 1]] + K) {
				++pre;
			}

			if (i > 0)
				dp[i] = dp[i - 1];
			dp[i] = Math.max(dp[i], D[pendingIndex[i]] + (pre >= 0 ? dp[pre] : 0));
		}
		long sum = 0;
		for (int i = 0; i < N; ++i) {
			if (D[i] <= max) {
				sum += D[i];
			}
		}
		System.out.println(sum - (pos > 0 ? dp[pos - 1] : 0));

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0