Chicken Farm

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

문제

Askhat is a young businessman. He realized that programming is not a very profitable business. Therefore, he decided to start a chicken farm.

On his farm, there are nn chickens that stand in a row. The ii-th chicken can eat no more than a_ia\_i grains. There are mm feeders, each one is described by the numbers l_jl\_j, r_jr\_j and c_jc\_j. Chicken ii can eat from feeder jj, if l_jir_jl\_j \le i \le r\_j, and all chickens in total can eat no more than c_jc\_j grains from the jj-th feeder.

As in any business, problems arise from nowhere. This time the government inspector came to his farm. He said that by current regulations, there should be at least two chickens that can eat from all feeders. In other words, there should be an integer ii such that 1in11 \le i \le n - 1, and for all feeders l_jil\_j \le i and i+1r_ji + 1 \le r\_j. All feeders that don’t satisfy this property will be destroyed. Askhat asks you to find for each ii what the maximum number of grains can be fed to chickens if you leave only feeders, from which chickens ii and i+1i + 1 can eat.

입력

The first line contains a single integer tt — the number of tests in the input (1t2,0001 \le t \le 2\\,000).

The following lines describe the given tests. The first line of each test contains two integers nn and mm — the number of chickens and the number of feeders, respectively (1n2,0001 \le n \le 2\\,000, 1m100,0001 \le m \le 100\\,000). The following line contains nn integers a_ia\_i — the maximum number of grains that the ii-th chicken can eat (0a_i1090 \le a\_i \le 10^9). The following mm lines contain three integers each l_jl\_j, r_jr\_j, and c_jc\_j describing the jj-th feeder (1l_jr_jn1 \le l\_j \le r\_j \le n, 0c_j1090 \le c\_j \le 10^9).

The total sum of all nn in the input doesn’t exceed 2,0002\\,000.

The total sum of all mm in the input doesn’t exceed 100,000100\\,000.

The total sum of all n mn \cdot m in the input doesn’t exceed 10710^7.

출력

For each test print n1n-1 integers: the ii-th of these integers should equal to the maximum number of grains that can be fed to chickens if you leave only feeders with l_jil\_j \le i and r_ji+1r\_j \ge i + 1.

힌트

If you leave the feeders, from which chickens 11 and 22 can eat, then only the first feeder will remain. In this case, you can feed the first chicken all the grains from it, and four grains will be fed.

Similarly, if you leave the feeders, from which the second and third chickens can eat.

If you leave the feeders, from which chickens 33 and 44 can eat, then all the feeders will remain. Then you can feed the first chicken grains from the first feeder, and the third and fourth chickens grains from the remaining feeders. Thus, nine grains will be fed.

In the last case, you leave the feeders, from which chickens 44 and 55 can eat. Only the second feeder will remain. You can feed all grains from it.