結果

問題 No.2248 max(C)-min(C)
ユーザー mkawa2mkawa2
提出日時 2023-03-17 22:05:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 792 ms / 3,000 ms
コード長 1,288 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 131,736 KB
最終ジャッジ日時 2023-10-18 14:53:53
合計ジャッジ時間 16,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,436 KB
testcase_01 AC 41 ms
55,436 KB
testcase_02 AC 44 ms
55,436 KB
testcase_03 AC 49 ms
63,848 KB
testcase_04 AC 48 ms
61,424 KB
testcase_05 AC 44 ms
55,436 KB
testcase_06 AC 61 ms
68,536 KB
testcase_07 AC 61 ms
68,540 KB
testcase_08 AC 63 ms
70,612 KB
testcase_09 AC 62 ms
68,544 KB
testcase_10 AC 45 ms
55,436 KB
testcase_11 AC 61 ms
68,540 KB
testcase_12 AC 50 ms
63,784 KB
testcase_13 AC 58 ms
68,524 KB
testcase_14 AC 62 ms
68,540 KB
testcase_15 AC 66 ms
70,628 KB
testcase_16 AC 50 ms
63,848 KB
testcase_17 AC 63 ms
68,560 KB
testcase_18 AC 186 ms
123,656 KB
testcase_19 AC 78 ms
79,300 KB
testcase_20 AC 207 ms
131,736 KB
testcase_21 AC 201 ms
129,428 KB
testcase_22 AC 162 ms
99,672 KB
testcase_23 AC 128 ms
92,872 KB
testcase_24 AC 87 ms
82,652 KB
testcase_25 AC 198 ms
124,432 KB
testcase_26 AC 189 ms
103,200 KB
testcase_27 AC 192 ms
124,504 KB
testcase_28 AC 78 ms
77,564 KB
testcase_29 AC 192 ms
123,428 KB
testcase_30 AC 122 ms
91,512 KB
testcase_31 AC 210 ms
131,360 KB
testcase_32 AC 94 ms
84,304 KB
testcase_33 AC 109 ms
90,748 KB
testcase_34 AC 226 ms
131,356 KB
testcase_35 AC 228 ms
131,732 KB
testcase_36 AC 215 ms
131,360 KB
testcase_37 AC 136 ms
97,592 KB
testcase_38 AC 616 ms
109,284 KB
testcase_39 AC 603 ms
109,280 KB
testcase_40 AC 615 ms
109,420 KB
testcase_41 AC 536 ms
104,848 KB
testcase_42 AC 611 ms
109,412 KB
testcase_43 AC 560 ms
104,988 KB
testcase_44 AC 602 ms
109,124 KB
testcase_45 AC 490 ms
102,388 KB
testcase_46 AC 303 ms
95,660 KB
testcase_47 AC 616 ms
109,420 KB
testcase_48 AC 549 ms
120,680 KB
testcase_49 AC 781 ms
129,804 KB
testcase_50 AC 792 ms
129,472 KB
testcase_51 AC 791 ms
129,808 KB
testcase_52 AC 783 ms
129,736 KB
testcase_53 AC 190 ms
83,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

from collections import deque
from heapq import *

n = II()
aa = LI()
bb = LI()

for i in range(n):
    if aa[i] > bb[i]:
        aa[i], bb[i] = bb[i], aa[i]

hp = []
mx = -inf
for i, a in enumerate(aa):
    heappush(hp, (a, i))
    mx = max(mx, a)

ans = mx-hp[0][0]
while 1:
    a, i = heappop(hp)
    if a == bb[i]: break
    if a == (aa[i]+bb[i])//2:
        heappush(hp, (bb[i], i))
        mx = max(mx, bb[i])
    elif a == aa[i]:
        c = (aa[i]+bb[i])//2
        heappush(hp, (c, i))
        mx = max(mx, c)
    ans = min(ans, mx-hp[0][0])

print(ans)
0