結果
| 問題 | No.2248 max(C)-min(C) | 
| コンテスト | |
| ユーザー |  ntuda | 
| 提出日時 | 2023-03-19 09:05:08 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2,862 ms / 3,000 ms | 
| コード長 | 672 bytes | 
| コンパイル時間 | 423 ms | 
| コンパイル使用メモリ | 82,032 KB | 
| 実行使用メモリ | 238,056 KB | 
| 最終ジャッジ日時 | 2024-09-25 17:56:53 | 
| 合計ジャッジ時間 | 44,901 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 51 | 
ソースコード
from heapq import *
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = set()
E = []
Q = []
cmax = 0
for i in range(N):
    a = A[i]
    b = B[i]
    if a > b:
        a, b = b, a
    c = (a + b) // 2
    d = (a, (a + b) // 2, b)
    E.append(d)
    D |= set(d)
    Q.append((a, i, 0))
    if cmax < a:
        cmax = a
D = sorted(list(D))
heapify(Q)
ans = 10 ** 9
for d in D:
    while d > Q[0][0]:
        _, i, j = heappop(Q)
        if j == 2:
            print(ans)
            exit()
        add = E[i][j + 1]
        if cmax < add:
            cmax = add
        heappush(Q, (add, i, j + 1))
    ans = min(ans, cmax - d)
            
            
            
        