Problem:
Score : 500 points

Problem Statement

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.

Constraints

All values in input are integers.

1 \leq N, Q \leq 2 \times 10^5

0 \leq S_i < T_i \leq 10^9

1 \leq X_i \leq 10^9

0 \leq D_1 < D_2 < ... < D_Q \leq 10^9

If i \neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.

Input

Input is given from Standard Input in the following format:

N Q
S_1 T_1 X_1
:
S_N T_N X_N
D_1
:
D_Q

Output

Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.

Sample Input 1

4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8

Sample Output 1

2
2
10
-1
13
-1

The first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.

The second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.

The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.

Solution in PyPy3 (2.4.0) (judge verdict: Time Limit Exceeded)

#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import collections
import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


class Node:

    def __init__(self, start, end):
        self.start, self.end, self.mid = start, end, (start + end) // 2
        self.val = float('inf')
        self.left = self.right = None


class NumArray:

    def __init__(self, x):
        x.sort()
        self.x_i = {v: i for i, v in enumerate(x)}

        def createTree(l, r):
            if l >= r:
                return None
            root = Node(l, r)
            if l + 1 == r:
                return root
            mid = root.mid
            root.left = createTree(l, mid)
            root.right = createTree(mid, r)
            return root

        self.root = createTree(0, len(x) - 1)

    def update(self, x1, x2, val):
        def updateVal(root, i, j):
            if root.start == i and root.end == j:
                root.val = min(root.val, val)
            else:
                mid = root.mid
                if i < mid:
                    updateVal(root.left, i, min(mid, j))
                if mid < j:
                    updateVal(root.right, max(mid, i), j)

        return updateVal(self.root, self.x_i[x1], self.x_i[x2])

    def query(self, x):
        def queryVal(root, i):
            if not root or i < root.start or i >= root.end:
                return float('inf')
            else:
                return min(root.val, queryVal(root.left, i), queryVal(root.right, i))

        return queryVal(self.root, self.x_i[x])


def main():
    N, Q = read_int_array()
    updates = []
    for i in range(N):
        S, T, X = read_int_array()
        updates.append((S - X, 1, X))
        updates.append((T - X, -1, X))

    active = []
    to_delete = collections.defaultdict(int)
    import heapq
    heapq.heapify(updates)
    for _ in range(Q):
        x = read_int()
        while updates and updates[0][0] <= x:
            coord, tp, val = heapq.heappop(updates)

            if tp == -1:
                to_delete[val] += 1
            else:
                heapq.heappush(active, val)

            while active and to_delete[active[0]] > 0:
                to_delete[active[0]] -= 1
                heapq.heappop(active)
        print(active[0] if active else -1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion


def read():
    return input()


def read_array(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)


def read_int():
    return int(read())


def read_int_array(sep=None, maxsplit=-1):
    return [int(a) for a in read_array(sep, maxsplit)]


if __name__ == "__main__":
    main()