Problem: There is an infinitely long street that runs west to east, which we consider as a number line.  There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.  Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.  Find the distance each of the Q people will walk.

Submission attempts (in order):
import sys
from operator import itemgetter
from heapq import heapify, heappush, heappop

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
queue = []

for S, T, X in zip(*[iter(STX)] * 3):
    s = S - X - 0.5
    t = T - X - 0.5
    queue.append((s, t, X))
    queue.append((t, s, -X))

for D in STXD[3 * N:]:
    queue.append((D, 0, 0))

queue.sort(key=itemgetter(0), reverse=True)
heap = []
heapify(heap)
S, T, stop = 0, 0, -1
not_available = set()
while queue:
    s, t, x = queue.pop()
    if x == 0:
        print(stop)
    elif x < 0:
        s, t = t, s
        not_available.add((s, t, -x))
        if stop == -x:
            while heap:
                s, t, stop = heappop(heap)
                if (s, t, stop) not in not_available:
                    break
            else:
                stop = -1
    else:
        if stop != -1:
            if stop < x:
                heappush(heap, (s, t, x))
            else:
                heappush(heap, (S, T, stop))
                S, T, stop = s, t, x
        else:
            S, T, stop = s, t, x


import sys
from operator import itemgetter

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
D = STXD[3 * N:]
queue = []

for S, T, X in zip(*[iter(STX)] * 3):
    S -= X
    T -= X
    queue.append((S, T, X))

queue.sort(key=itemgetter(2))



import sys
import numpy as np

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = np.array(STXD[:3 * N], np.int64)
S = STX[::3]
T = STX[1::3]
X = STX[2::3]
arg = np.argsort(X)
X = X[arg]
S = S[arg]
T = T[arg]
D = np.array(STXD[3 * N:], np.int64)

s = S - X
t = T - X
STX = list(zip(s.tolist(), t.tolist(), X.tolist()))

import sys
import numpy as np

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = np.array(STXD[:3 * N], np.int64)
S = STX[::3]
T = STX[1::3]
X = STX[2::3]
arg = np.argsort(X)
X = X[arg]
S = S[arg]
T = T[arg]
D = np.array(STXD[3 * N:], np.int64)

s = S - X
t = T - X


import sys
from operator import itemgetter
from heapq import heapify, heappush, heappop

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
queue = []

for S, T, X in zip(*[iter(STX)] * 3):
    queue.append((S - X - 0.5, X))
    queue.append((T - X - 0.5, -X))

for D in STXD[3 * N:]:
    queue.append((D, 0))

queue.sort(key=itemgetter(0), reverse=True)
heap = []
heapify(heap)
stop = -1
not_available = set()
while queue:
    t, x = queue.pop()
    if x == 0:
        print(stop)
    elif x < 0:
        not_available.add(-x)
        if stop == -x:
            while heap:
                stop = heappop(heap)
                if stop not in not_available:
                    break
            else:
                stop = -1
    else:
        if stop != -1:
            stop, x = min(stop, x), max(stop, x)
            heappush(heap, x)
        else:
            stop = x


import sys
from operator import itemgetter
from heapq import heapify, heappush, heappop

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
queue = []

for i, (S, T, X) in enumerate(zip(*[iter(STX)] * 3), 1):
    queue.append((S - X - 0.5, X, i))
    queue.append((T - X - 0.5, -X, i))

for D in STXD[3 * N:]:
    queue.append((D, 0, 0))

queue.sort(key=itemgetter(0), reverse=True)
heap = []
heapify(heap)
stop, construction = -1, 0
not_available = set()
while queue:
    _, x, n = queue.pop()
    if x == 0:
        print(stop)
    elif x < 0:
        not_available.add(n)
        if n == construction:
            while heap:
                stop, construction = heappop(heap)
                if construction not in not_available:
                    break
            else:
                stop, construction = -1, 0
    else:
        if stop != -1:
            if stop <= x:
                heappush(heap, (x, n))
            else:
                heappush(heap, (stop, construction))
                stop, construction = x, n
        else:
            stop, construction = x, n


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted