結果

問題 No.2248 max(C)-min(C)
コンテスト
ユーザー rlangevin
提出日時 2023-03-17 22:12:22
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,354 ms / 3,000 ms
コード長 829 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 217 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 172,564 KB
最終ジャッジ日時 2026-04-06 16:09:12
合計ジャッジ時間 37,329 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import *

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = []
for i in range(N):
    D.append((A[i], i))
    D.append((B[i], i))
    D.append(((A[i] + B[i])//2, i))
    
D.sort(reverse=True)
cnt = 0
L = [0] * N
ans = 10 ** 18
Q = deque()
while D:
    now = D[-1][0]
    while D:
        if D[-1][0] == now:
            _, ind = D.pop()
            Q.append((ind, now))
            L[ind] += 1
            if L[ind] == 1:
                cnt += 1
        else:
            break
    
    while cnt == N:
        val = Q[0][1]
        ans = min(ans, abs(Q[0][1] - Q[-1][-1]))
        while Q[0][1] == val:
            ind, _ = Q.popleft()
            L[ind] -= 1
            if L[ind] == 0:
                cnt -= 1
            if not Q:
                break
print(ans)
0