結果

問題 No.3072 Speedrun Query
ユーザー titia
提出日時 2025-03-21 22:55:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 733 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,432 KB
最終ジャッジ日時 2025-03-21 22:55:50
合計ジャッジ時間 11,993 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 TLE * 3 -- * 16
権限があれば一括ダウンロードができます

ソースコード

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