Moo Route II

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

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 NN airports numbered 1,2,,N1, 2, \ldots, N and MM time-traveling flights (1N,M2000001\leq N, M \leq 200000). Flight jj leaves airport c_jc\_j at time r_jr\_j, and arrives in airport d_jd\_j at time s_js\_j (0r_j,s_j1090 \leq r\_j, s\_j \leq 10^9, s_j<r_js\_j < r\_j is possible). In addition, she must leave a_ia\_i time for a layover at airport ii (1a_i1091\le a\_i\le 10^9). (That is to say, if Bessie takes a flight arriving in airport ii at time ss, she can then transfer to a flight leaving the airport at time rr if rs+a_ir \geq s + a\_i. The layovers do not affect when Bessie arrives at an airport.)

Bessie starts at city 11 at time 00. For each airport from 11 to NN, what is the earliest time when Bessie can get to at it?

입력

The first line of input contains NN and MM.

The next MM lines describe flights. The jjth of these lines contains c_jc\_j, r_jr\_j, d_jd\_j, s_js\_j in that order. (1c_j,d_jN1\leq c\_j, d\_j \leq N, 0r_j,s_j1090\leq r\_j, s\_j \leq 10^9)

The next line describes airports. It contains NN space separated integers, a_1,,a_Na\_1, \ldots, a\_N.

출력

There are NN lines of output. Line ii contains the earliest time when Bessie can get to airport ii, or -1 if it is not possible for Bessie to get to that airport.