結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | 37zigen |
提出日時 | 2016-11-17 17:41:07 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,124 bytes |
コンパイル時間 | 3,373 ms |
コンパイル使用メモリ | 78,804 KB |
実行使用メモリ | 59,068 KB |
最終ジャッジ日時 | 2024-11-26 03:04:29 |
合計ジャッジ時間 | 27,060 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 108 ms
40,124 KB |
testcase_01 | RE | - |
testcase_02 | AC | 107 ms
40,192 KB |
testcase_03 | RE | - |
testcase_04 | AC | 166 ms
42,040 KB |
testcase_05 | AC | 169 ms
42,308 KB |
testcase_06 | AC | 178 ms
42,952 KB |
testcase_07 | AC | 167 ms
42,280 KB |
testcase_08 | AC | 170 ms
42,060 KB |
testcase_09 | AC | 174 ms
42,392 KB |
testcase_10 | AC | 157 ms
41,976 KB |
testcase_11 | AC | 170 ms
43,112 KB |
testcase_12 | AC | 162 ms
42,548 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)); } }