#U2223FS3. Moo Route II
Moo Route II
题目描述
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 if it is not possible for Bessie to get to that airport.
样例 #1
样例输入 #1
3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
样例输出 #1
0
0
20
样例 #2
样例输入 #2
3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
样例输出 #2
0
10
-1
提示
Explanation for Sample 1
Bessie can take the flights in the listed order, which allows her to arrive at airports and at time , and airport at time .
Note that this route passes through airport twice, first from time and then from time .
Explanation for Sample 2
In this case, Bessie can take flight , arriving at airport at time . However, she does not arrive in time to also take flight , since the departure time is and she cannot make a time-unit layover.
SCORING
- Inputs : for all , i.e. all flights arrive after they depart.
- Inputs :
- Inputs : No additional constraints.