#623
Unrated
Moo Route II
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 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

예제 출력 1

0
0
20

예제 입력 2

3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10

예제 출력 2

0
10
-1

점수

Inputs 3-5: rj<sjr_j < s_j for all jj, i.e. all flights arrive after they depart.Inputs 6-10: N,M5000N, M \leq 5000Inputs 11-20: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.