아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Chicken Farm

시간 제한1초메모리 제한512 MB

요약
인접한 두 닭 사이의 각 경계마다 그 경계를 가로지르는 먹이통만 남기고 닭들이 먹을 수 있는 곡물의 최대 총량을 구한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 누적 합, 수학
정답자
아직 제출이 없습니다

문제

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_j≤i≤r_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 1≤i≤n−11 \le i \le n - 1, and for all feeders l_j≤il\_j \le i and i+1≤r_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 (1≤t≤2,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 (1≤n≤2,0001 \le n \le 2\\,000, 1≤m≤100,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 (0≤a_i≤1090 \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 (1≤l_j≤r_j≤n1 \le l\_j \le r\_j \le n, 0≤c_j≤1090 \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 n−1n-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_j≤il\_j \le i and r_j≥i+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.

예제1

  1. 예제 1

    입력
    1
    5 3
    5 2 2 3 1
    1 4 4
    3 5 4
    3 4 1
    
    예상 출력
    4 4 9 4