結果

問題 No.2248 max(C)-min(C)
ユーザー titia
提出日時 2023-03-17 22:03:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,200 ms / 3,000 ms
コード長 578 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 142,840 KB
最終ジャッジ日時 2024-12-20 09:58:03
合計ジャッジ時間 40,630 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

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


N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

X=[]

for i in range(N):
    Y=[A[i],B[i],(A[i]+B[i])//2]
    Y.sort()
    X.append(tuple(Y))

ANS=1<<31

MAX=0
for x in X:
    MAX=max(MAX,x[0])

X.sort()
MIN=1<<31

while X:
    k=list(heappop(X))

    ANS=min(ANS,MAX-min(MIN,k[0]))

    if MIN!=1<<31:
        break

    u=k.pop(0)

    if len(k)==0:
        MIN=min(MIN,u)
        
    else:
        heappush(X,tuple(k))
        MAX=max(MAX,k[0])

print(ANS)
0