Drones

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

문제

A farmer grows rare flowers, which are located on a line. The total number of flowers is nn, and each flower f_if\_i has a location x_ix\_i on the line. Each flower can be considered as a point on the line. In order to nourish the flowers, the farmer fertilizes them regularly. So the farmer will rent several fertilizer drones.

The drones spray fertilizer on the ground as they fly. The flight trajectory of each drone is a line segment, which can be considered as a closed interval. There are mm given drones D_iD\_i with intervals \[a_i,b_i]\[a\_i, b\_i], each of which has a cost c_ic\_i. We should choose a set of drones such that each of the given points is contained in at least one of the chosen intervals, that is, the union of the chosen intervals contains all the points. The set of drones satisfying this condition is said to be a candidate set of drones.

We assume that all the points and the endpoints of all the intervals have distinct coordinates. We say that a point is covered by an interval, if it is contained in the interval. For a candidate set XX of drones, the cost paid to each point is defined to be the sum of the costs of intervals in CC which cover the point. Our goal is to find an optimal set of drones, minimizing the maximum cost of points among all the candidate sets.

For example, there are five points on a line and four given intervals as shown in the above figure. In this figure, the numbers on the intervals represent their costs. All possible candidate sets of intervals are \[1,5],\[6,10],\[8,13],\[1,5],\[3,11],\[8,13]\\{\[1, 5],\[6, 10], \[8, 13]\\}, \\{\[1, 5],\[3, 11], \[8, 13]\\}, and the set with all of four intervals. For the first set, the point located at 99 has the cost 44, which is the maximum cost of points. For the second and the third set, the same point has the costs 33 and 55, respectively, which are the maximum. Thus the cost 33 is the minimum of the maximum cost of points among all the candidate sets.

Given the locations of nn points and mm intervals with their costs, write a program to output the minimum of the maximum cost of points among all the candidate sets of drones.

입력

Your program is to read from standard input. The input starts with a line containing two integers, nn and mm (n1n \ge 1, 2n+m100,0002 \le n + m \le 100,000, 1m 2,0001 \le m \le 2,000), where nn is the number of points and mm is the number of intervals. The second line contains nn integers, representing the locations of points, where the integers are between 00 and 10910^9. In the following mm lines, each line contains three integers aa, bb, and cc, representing an interval \[a,b]\[a, b] with a cost cc (0a<b1090 \le a < b \le 10^9 and 1c1091 \le c \le 10^9). Note that all the points and the endpoints of all the intervals have distinct coordinates.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the minimum of the maximum cost of points among all the candidate sets of drones. If there is no candidate set of drones, then the line should contain -1.