結果

問題 No.2248 max(C)-min(C)
ユーザー lloyzlloyz
提出日時 2023-03-22 00:07:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 798 ms / 3,000 ms
コード長 666 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 143,796 KB
最終ジャッジ日時 2023-10-18 18:39:56
合計ジャッジ時間 16,731 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,508 KB
testcase_01 AC 38 ms
53,508 KB
testcase_02 AC 38 ms
53,508 KB
testcase_03 AC 47 ms
61,928 KB
testcase_04 AC 43 ms
59,504 KB
testcase_05 AC 40 ms
53,508 KB
testcase_06 AC 58 ms
66,648 KB
testcase_07 AC 59 ms
68,716 KB
testcase_08 AC 61 ms
68,740 KB
testcase_09 AC 60 ms
68,708 KB
testcase_10 AC 39 ms
53,508 KB
testcase_11 AC 59 ms
68,712 KB
testcase_12 AC 46 ms
61,864 KB
testcase_13 AC 56 ms
66,644 KB
testcase_14 AC 60 ms
68,716 KB
testcase_15 AC 63 ms
68,748 KB
testcase_16 AC 46 ms
61,928 KB
testcase_17 AC 62 ms
68,732 KB
testcase_18 AC 190 ms
117,472 KB
testcase_19 AC 77 ms
79,776 KB
testcase_20 AC 216 ms
143,212 KB
testcase_21 AC 212 ms
143,020 KB
testcase_22 AC 164 ms
109,036 KB
testcase_23 AC 131 ms
95,964 KB
testcase_24 AC 86 ms
83,720 KB
testcase_25 AC 196 ms
117,180 KB
testcase_26 AC 194 ms
113,504 KB
testcase_27 AC 196 ms
117,288 KB
testcase_28 AC 74 ms
77,716 KB
testcase_29 AC 196 ms
117,652 KB
testcase_30 AC 121 ms
93,160 KB
testcase_31 AC 218 ms
143,788 KB
testcase_32 AC 91 ms
85,600 KB
testcase_33 AC 108 ms
90,904 KB
testcase_34 AC 233 ms
143,364 KB
testcase_35 AC 234 ms
143,248 KB
testcase_36 AC 218 ms
143,796 KB
testcase_37 AC 140 ms
102,860 KB
testcase_38 AC 631 ms
122,540 KB
testcase_39 AC 615 ms
122,544 KB
testcase_40 AC 619 ms
122,552 KB
testcase_41 AC 528 ms
116,752 KB
testcase_42 AC 607 ms
122,548 KB
testcase_43 AC 548 ms
116,444 KB
testcase_44 AC 602 ms
122,340 KB
testcase_45 AC 489 ms
112,120 KB
testcase_46 AC 297 ms
98,628 KB
testcase_47 AC 619 ms
122,552 KB
testcase_48 AC 552 ms
133,672 KB
testcase_49 AC 798 ms
142,988 KB
testcase_50 AC 792 ms
142,936 KB
testcase_51 AC 792 ms
142,992 KB
testcase_52 AC 787 ms
142,988 KB
testcase_53 AC 185 ms
84,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = []
for i in range(n):
    if A[i] > B[i]:
        A[i], B[i] = B[i], A[i]
    M.append((A[i] + B[i]) // 2)
H = []
max_ = -10**18
for i in range(n):
    heappush(H, (A[i], i))
    max_ = max(max_, A[i])
ans = max_ - H[0][0]
while True:
    x, i = heappop(H)
    if x == B[i]:
        break
    elif x == M[i]:
        heappush(H, (B[i], i))
        max_ = max(max_, B[i])
    else:
        heappush(H, (M[i], i))
        max_ = max(max_, M[i])
    ans = min(ans, max_ - H[0][0])
print(ans)
0