結果

問題 No.2248 max(C)-min(C)
ユーザー cologne
提出日時 2023-03-21 13:58:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,991 ms / 3,000 ms
コード長 542 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 166,256 KB
最終ジャッジ日時 2024-09-18 14:21:30
合計ジャッジ時間 29,025 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq


def main():
    N = int(input())
    *A, = map(int, input().split())
    *B, = map(int, input().split())
    Q = []
    for i in range(N):
        heapq.heappush(Q, sorted([A[i], B[i], (A[i]+B[i])//2]))
    mx, mn = max(Q)[0], Q[0][0]
    ans = mx-mn
    while True:
        a = heapq.heappop(Q)
        if len(a) == 1:
            print(ans)
            return
        a = a[1:]
        mx = max(mx, a[0])
        heapq.heappush(Q, a)
        mn = Q[0][0]
        ans = min(ans, mx-mn)


if __name__ == '__main__':
    main()
0