結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | 37zigen |
提出日時 | 2016-11-17 17:41:07 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,124 bytes |
コンパイル時間 | 3,930 ms |
コンパイル使用メモリ | 79,372 KB |
実行使用メモリ | 59,572 KB |
最終ジャッジ日時 | 2024-05-04 14:54:14 |
合計ジャッジ時間 | 25,826 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
41,108 KB |
testcase_01 | RE | - |
testcase_02 | AC | 95 ms
39,912 KB |
testcase_03 | RE | - |
testcase_04 | AC | 151 ms
41,608 KB |
testcase_05 | AC | 153 ms
42,156 KB |
testcase_06 | AC | 163 ms
43,152 KB |
testcase_07 | AC | 156 ms
42,084 KB |
testcase_08 | AC | 148 ms
41,728 KB |
testcase_09 | AC | 160 ms
42,364 KB |
testcase_10 | AC | 150 ms
41,904 KB |
testcase_11 | AC | 155 ms
42,872 KB |
testcase_12 | AC | 168 ms
42,624 KB |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
ソースコード
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 <= 1000; assert 1 <= K && K <= 1_000_00; for (int i = 0; i < N; ++i) { assert 1 <= T[i] && T[i] <= 1_000_00; assert 1 <= D[i] && D[i] <= 1_000_00; 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)); } }