PivotOJ

Moo Route II

시간 제한: 4000ms메모리 제한: 1024MB출처: USACO 2023 February SilverBOJ 27848

문제

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 cjc_j at time rjr_j, and arrives in airport djd_j at time sjs_j (0rj,sj1090 \leq r_j, s_j \leq 10^9, sj<rjs_j < r_j is possible). In addition, she must leave aia_i time for a layover at airport ii (1ai1091\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+air \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 cjc_j, rjr_j, djd_j, sjs_j in that order. (1cj,djN1\leq c_j, d_j \leq N, 0rj,sj1090\leq r_j, s_j \leq 10^9)

The next line describes airports. It contains NN space separated integers, a1,,aNa_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.

예제

예제 1

입력
3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
출력
0
0
20

예제 2

입력
3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
출력
0
10
-1
코드를 제출하려면 로그인하세요.