結果

問題 No.2248 max(C)-min(C)
コンテスト
ユーザー rlangevin
提出日時 2023-03-17 22:12:22
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,397 ms / 3,000 ms
+ 913µs
コード長 829 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 84 ms
コンパイル使用メモリ 64,128 KB
実行使用メモリ 119,308 KB
最終ジャッジ日時 2026-11-08 10:31:05
合計ジャッジ時間 43,358 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

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