Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect

#%%
a,b,q = map(int, input().split())
INF = 10**18
shrines = [-INF] + [int(input() for _ in range(a))] + [INF]
temples = [-INF] + [int(input() for _ in range(b))] + [INF]

for _ in range(q):

    start = int(input())

    
    shrine_east = shrines[bisect.bisect_right(shrines, start)]
    
    temple_east = temples[bisect.bisect_right(temples, start)]

    
    shrine_west = shirines[bisect.bisect_right(shrines, start) - 1]
    
    temple_west = temples[bisect.bisect_right(temples, start) - 1]

    ans = INF

    for shrine in [shrine_east, shrine_west]:
        for temple in [temple_east,temple_west]:
            cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)
            ans = min(ans,cur)

    print(ans)


#%%
import bisect

#%%
a,b,q = map(int, input().split())
INF = 10**18
shrines = [-INF] + [int(input() for _ in range(a))] + [INF]
temples = [-INF] + [int(input() for _ in range(b))] + [INF]

for _ in range(q):

    start = int(input())

    
    shrine_east = shrines[bisect.bisect_right(shrines, start)]
    
    temple_east = temples[bisect.bisect_right(temples, start)]

    
    shrine_west = shrines[bisect.bisect_right(shrines, start) - 1]
    
    temple_west = temples[bisect.bisect_right(temples, start) - 1]

    ans = INF

    for shrine in [shrine_east, shrine_west]:
        for temple in [temple_east,temple_west]:
            cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)
            ans = min(ans,cur)

    print(ans)



#%%
arr = [4,8,12,16,20]

#%%
bisect.bisect_left(arr,12)

#%%
bisect.bisect_right(arr,12)

#%%


#%%
import numpy as np
#%%

s,t,q = list(map(int, input().split()))
shrines = []
temples = []
questions = []
answers = []
dist = np.empty((s,t),dtype='int64')

for _ in range(s):
    shrines.append(int(input()))
shrines = np.array(shrines)

for _ in range(t):
    temples.append(int(input()))
temples = np.array(temples)

for _ in range(q):
    questions.append(int(input()))

for i, shrine in enumerate(shrines):
    dist[i]= [abs(shrine - temple) for temple in temples]

#%%
print(shrines,temples,dist)

#%%
for start in questions:
    min_shrine_start = float('inf')
    min_temple_start = float('inf')

    for i, st_s in enumerate(shrines - start):
        abs_st_s = abs(st_s)

        if abs_st_s < min_shrine_start:
            abs_st_s += np.min(dist[i])

            if abs_st_s < min_shrine_start:
                min_shrine_start = abs_st_s

    for j, st_t in enumerate(temples - start):
        abs_st_t = abs(st_t)

        if abs_st_t < min_temple_start:
            abs_st_t += np.min(dist[:,j])

            if abs_st_t < min_temple_start:
                min_temple_start = abs_st_t
    
    answers.append(min(min_shrine_start,min_temple_start))


for ans in answers:
    print(ans)


#%%
import bisect

#%%
a,b,q = map(int, input().split())
INF = 10**18
shrines = [-INF] + [int(input()) for _ in range(a)] + [INF]
temples = [-INF] + [int(input()) for _ in range(b)] + [INF]

for _ in range(q):

    start = int(input())

    
    shrine_east = shrines[bisect.bisect_right(shrines, start)]
    
    temple_east = temples[bisect.bisect_right(temples, start)]

    
    shrine_west = shrines[bisect.bisect_right(shrines, start) - 1]
    
    temple_west = temples[bisect.bisect_right(temples, start) - 1]

    ans = INF

    for shrine in [shrine_east, shrine_west]:
        for temple in [temple_east,temple_west]:
            cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)
            ans = min(ans,cur)

    print(ans)



Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted