1992: [USACO 2023 February Contest Silver] Problem 3. Moo Route II
题目描述
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 next lines describe flights. The th of these lines contains , , , in that order. (, )
The next line describes airports. It contains space separated integers, .
输出
样例输入
3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
样例输出
0
0
20
提示
Bessie can take the 3 flights in the listed order, which allows her to arrive at airports 1 and 2 at time 0, and airport 3 at time 20.
Note that this route passes through airport 2 twice, first from time 10-11 and then from time 0-1.
SAMPLE INPUT:
3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
SAMPLE OUTPUT:
0
10
-1
In this case, Bessie can take flight 1, arriving at airport 2 at time 10. However, she does not arrive in time to also take flight 2, since the departure time is 10 and she cannot make a 1 time-unit layover.
SCORING:
- Inputs 3-5: for all , i.e. all flights arrive after they depart.
- Inputs 6-10:
- Inputs 11-20: No additional constraints.