結果

問題 No.2248 max(C)-min(C)
ユーザー titia
提出日時 2023-03-17 21:59:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 2,990 ms / 3,000 ms
コード長 544 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 57,468 KB
最終ジャッジ日時 2024-09-18 10:55:23
合計ジャッジ時間 80,356 ms
ジャッジサーバーID
(参考情報)
judge1 / 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]))

    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