結果

問題 No.3072 Speedrun Query
ユーザー titia
提出日時 2025-03-21 22:55:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,311 ms / 2,500 ms
コード長 733 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,632 KB
実行使用メモリ 158,508 KB
最終ジャッジ日時 2025-03-21 22:56:15
合計ジャッジ時間 21,589 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from bisect import bisect

N,KA,KB=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))


def search_near(A,s):
    k=1<<30
    x=bisect(A,s)
    for i in range(x-1,x+2):
        if 0<=i<len(A):
            k=min(k,abs(s-A[i]))
    return k

AB=1<<30
for b in B:
    k=search_near(A,b)
    AB=min(AB,k)

Q=int(input())

for tests in range(Q):
    s,t=map(int,input().split())

    ANS=abs(s-t)

    # Aを使う

    k=search_near(A,s)
    l=search_near(A,t)

    ANS=min(ANS,k+l)

    # Bを使う

    m=search_near(B,s)
    n=search_near(B,t)

    ANS=min(ANS,m+n)

    ANS=min(ANS,k+AB+n)
    ANS=min(ANS,l+AB+m)

    print(ANS)

    

    
    

    
0