結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | 37zigen |
提出日時 | 2016-11-17 17:18:49 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,305 ms / 2,000 ms |
コード長 | 2,149 bytes |
コンパイル時間 | 3,709 ms |
コンパイル使用メモリ | 79,564 KB |
実行使用メモリ | 60,200 KB |
最終ジャッジ日時 | 2024-06-11 19:29:12 |
合計ジャッジ時間 | 32,559 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 130 ms
41,548 KB |
testcase_01 | AC | 133 ms
41,536 KB |
testcase_02 | AC | 132 ms
41,516 KB |
testcase_03 | AC | 134 ms
41,432 KB |
testcase_04 | AC | 188 ms
42,132 KB |
testcase_05 | AC | 190 ms
42,788 KB |
testcase_06 | AC | 198 ms
43,164 KB |
testcase_07 | AC | 187 ms
42,168 KB |
testcase_08 | AC | 187 ms
42,280 KB |
testcase_09 | AC | 196 ms
42,692 KB |
testcase_10 | AC | 178 ms
41,920 KB |
testcase_11 | AC | 198 ms
42,736 KB |
testcase_12 | AC | 195 ms
42,904 KB |
testcase_13 | AC | 561 ms
48,260 KB |
testcase_14 | AC | 590 ms
48,536 KB |
testcase_15 | AC | 817 ms
53,176 KB |
testcase_16 | AC | 1,013 ms
58,136 KB |
testcase_17 | AC | 1,046 ms
58,780 KB |
testcase_18 | AC | 541 ms
48,316 KB |
testcase_19 | AC | 1,250 ms
58,648 KB |
testcase_20 | AC | 719 ms
50,292 KB |
testcase_21 | AC | 1,190 ms
58,792 KB |
testcase_22 | AC | 726 ms
52,328 KB |
testcase_23 | AC | 1,168 ms
59,832 KB |
testcase_24 | AC | 658 ms
49,392 KB |
testcase_25 | AC | 1,264 ms
58,928 KB |
testcase_26 | AC | 512 ms
48,320 KB |
testcase_27 | AC | 1,031 ms
59,008 KB |
testcase_28 | AC | 979 ms
58,504 KB |
testcase_29 | AC | 751 ms
52,520 KB |
testcase_30 | AC | 1,254 ms
60,200 KB |
testcase_31 | AC | 539 ms
48,368 KB |
testcase_32 | AC | 593 ms
48,308 KB |
testcase_33 | AC | 1,189 ms
59,308 KB |
testcase_34 | AC | 1,253 ms
59,184 KB |
testcase_35 | AC | 1,264 ms
59,928 KB |
testcase_36 | AC | 1,305 ms
58,860 KB |
testcase_37 | AC | 1,253 ms
59,136 KB |
testcase_38 | AC | 1,190 ms
59,076 KB |
ソースコード
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]); } { assert 1 <= N && N <= 2 * 1_000_00; assert 1 <= K && K <= 1_000_000_000; for (int i = 0; i < N; ++i) { assert 1 <= T[i] && T[i] <= 1_000_000_000; assert 1 <= D[i] && D[i] <= 1_000_000_000; if (i + 1 < N) assert T[i] < T[i + 1]; } } 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)); sc.close(); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }