結果
| 問題 | No.2248 max(C)-min(C) | 
| コンテスト | |
| ユーザー |  hir355 | 
| 提出日時 | 2023-03-17 22:41:30 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2,317 ms / 3,000 ms | 
| コード長 | 646 bytes | 
| コンパイル時間 | 379 ms | 
| コンパイル使用メモリ | 81,780 KB | 
| 実行使用メモリ | 145,956 KB | 
| 最終ジャッジ日時 | 2024-09-18 11:50:08 | 
| 合計ジャッジ時間 | 32,906 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 51 | 
ソースコード
import heapq
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
    if a[i] > b[i]:
        a[i], b[i] = b[i], a[i]
hq = []
for i in range(n):
    heapq.heappush(hq, (a[i], i, 0))
ma = max(a)
ans = max(a) - min(a)
for _ in range(n * 2):
    x, i, j = heapq.heappop(hq)
    if ans > ma - x:
        ans = ma - x
    if j == 0:
        heapq.heappush(hq, ((a[i] + b[i]) // 2, i, 1))
        if ma < (a[i] + b[i]) // 2:
            ma = (a[i] + b[i]) // 2
    elif j == 1:
        heapq.heappush(hq, (b[i], i, 2))
        if ma < b[i]:
            ma = b[i]
    else:
        break
print(ans)
            
            
            
        