luogu#P9126. [USACO23FEB] Moo Route II S
[USACO23FEB] Moo Route II S
题目描述
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.
题目大意
题目描述
注意:本题的时间限制为 4 秒,是默认限制的两倍。
Bessie 正在度假!由于最近的技术进步,Bessie 可以通过先进的航班旅行,这些航班甚至可以进行时间旅行。此外,即使存在多个“平行”的 Bessie 同时出现也不会有任何问题。
在这个国家,有 个机场,编号为 ,以及 条时间旅行航班()。第 条航班从机场 在时间 起飞,并在时间 抵达机场 (, 是可能的)。此外,Bessie 在机场 需要停留 时间()。也就是说,如果 Bessie 乘坐一趟航班在时间 抵达机场 ,她可以转乘一趟从该机场出发的航班,只要该航班的起飞时间 。需要注意的是,停留时间不会影响 Bessie 抵达某机场的实际时间。
Bessie 从城市 出发,起始时间为 。对于从 到 的每个机场,求出 Bessie 最早可以到达该机场的时间。
输入格式
第一行输入包含两个整数 和 。
接下来的 行描述航班信息。其中第 行包含 ,依次表示航班的起飞机场、起飞时间、降落机场和降落时间。
接下来的 行描述每个机场的停留时间。该行包含 个用空格分隔的整数,分别为 。
输出格式
输出共 行。第 行输出 Bessie 最早到达机场 的时间;如果无法到达该机场,输出 。
样例 1 的解释
Bessie 可以按照给定的顺序乘坐第 班航班,这使她可以在时间 到达机场 和机场 ,以及在时间 到达机场 。
注意,这条路线会两次经过机场 ,第一次是在时间 ,第二次是在时间 。
样例 2 的解释
在这个例子中,Bessie 可以乘坐第 班航班,在时间 抵达机场 。但是,她无法及时赶上第 班航班,因为该航班的起飞时间为 ,而她需要至少 个时间单位来完成停留。
评分标准
- 测试点 :对于每个 ,,也就是说所有航班的到达时间晚于起飞时间。
- 测试点 :
- 测试点 :无额外限制。
3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
0
0
20
3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
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.