문제
Note: The time limit for this problem is 4s, twice the default.
Bessie is on vacation! Due to some recent technological advances, Bessie will travel via technologically sophisticated flights, which can even time travel. Furthermore, there are no issues if two "parallel" versions of Bessie ever meet.
In the country there are airports numbered and time-traveling flights (). Flight leaves airport at time , and arrives in airport at time (, is possible). In addition, she must leave time for a layover at airport (). (That is to say, if Bessie takes a flight arriving in airport at time , she can then transfer to a flight leaving the airport at time if . The layovers do not affect when Bessie arrives at an airport.)
Bessie starts at city at time . For each airport from to , what is the earliest time when Bessie can get to at it?
입력
The first line of input contains and .
The next lines describe flights. The th of these lines contains , , , in that order. (, )
The next line describes airports. It contains space separated integers, .
출력
There are lines of output. Line contains the earliest time when Bessie can get to airport , or -1 if it is not possible for Bessie to get to that airport.
예제 입력 1
3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
예제 출력 1
0
0
20
예제 입력 2
3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
예제 출력 2
0
10
-1
점수
Inputs 3-5: for all , i.e. all flights arrive after they depart.Inputs 6-10: Inputs 11-20: No additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인