結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | 37zigen |
提出日時 | 2016-11-17 15:44:43 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,831 bytes |
コンパイル時間 | 4,190 ms |
コンパイル使用メモリ | 78,524 KB |
実行使用メモリ | 64,820 KB |
最終ジャッジ日時 | 2024-05-04 14:51:26 |
合計ジャッジ時間 | 39,538 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
41,400 KB |
testcase_01 | AC | 135 ms
41,232 KB |
testcase_02 | AC | 135 ms
41,268 KB |
testcase_03 | AC | 137 ms
41,592 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 197 ms
42,400 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 1,042 ms
58,520 KB |
testcase_16 | AC | 1,227 ms
61,504 KB |
testcase_17 | AC | 1,259 ms
61,076 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 1,410 ms
61,304 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 1,017 ms
58,384 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 654 ms
48,236 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 1,361 ms
61,392 KB |
testcase_37 | WA | - |
testcase_38 | AC | 1,364 ms
61,624 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]); } 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; } preTime = T[i]; } } right = middle; } max = right; System.out.println(max); // SegTree seg = new SegTree(T[N - 1] + 1); SegTree seg = new SegTree(N); int preTime = -K; for (int i = 0; i < N; ++i) { if (D[i] <= max) { long opt = Math.max(seg.query(binarySearchUpper(T, preTime + K), binarySearchLower(T, T[i] - K) + 1), seg.query(binarySearchUpper(T, preTime), binarySearchUpper(T, preTime) + 1)); seg.setVal(i, opt + D[i]); } else { seg.setVal(i, seg.query(binarySearchUpper(T, preTime + K), binarySearchLower(T, T[i] - K) + 1)); preTime = T[i]; } } long sum = 0; for (int i = 0; i < N; ++i) { if (D[i] <= max) sum += D[i]; } System.out.println(sum - Math.max(seg.query(binarySearchUpper(T, preTime), binarySearchLower(T, preTime) + 1), seg.query(binarySearchUpper(T, preTime + K), N))); } static int binarySearchLower(int[] a, int key) { int left = -1; int right = a.length; while (right - left > 1) { int middle = (right + left) / 2; if (key >= a[middle]) { left = middle; } else { right = middle; } } return left; } static int binarySearchUpper(int[] a, int key) { int left = -1; int right = a.length; while (right - left > 1) { int middle = (right + left) / 2; if (key <= a[middle]) { right =middle; } else { left = middle; } } return right; } static class SegTree { int n = 1; long[] max; public SegTree(int n_) { while (n < n_) { n *= 2; } max = new long[2 * n - 1]; } void setVal(int k, long val) { k += n - 1; max[k] = val; while (k > 0) { k = (k - 1) / 2; max[k] = Math.max(max[2 * k + 1], max[2 * k + 2]); } } long query(int a, int b) { return query(a, b, 0, n, 0); } long query(int a, int b, int l, int r, int k) { if (a >= r || b <= l) { return 0; } else if (a <= l && r <= b) { return max[k]; } else { long vl = query(a, b, l, (l + r) / 2, 2 * k + 1); long vr = query(a, b, (l + r) / 2, r, 2 * k + 2); return Math.max(vl, vr); } } } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }