시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB0000.000%

문제

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 $n$ chickens that stand in a row. The $i$-th chicken can eat no more than $a_i$ grains. There are $m$ feeders, each one is described by the numbers $l_j$, $r_j$ and $c_j$. Chicken $i$ can eat from feeder $j$, if $l_j \le i \le r_j$, and all chickens in total can eat no more than $c_j$ grains from the $j$-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 $i$ such that $1 \le i \le n - 1$, and for all feeders $l_j \le i$ and $i + 1 \le r_j$. All feeders that don’t satisfy this property will be destroyed. Askhat asks you to find for each $i$ what the maximum number of grains can be fed to chickens if you leave only feeders, from which chickens $i$ and $i + 1$ can eat.

입력

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

The following lines describe the given tests. The first line of each test contains two integers $n$ and $m$ — the number of chickens and the number of feeders, respectively ($1 \le n \le 2\,000$, $1 \le m \le 100\,000$). The following line contains $n$ integers $a_i$ — the maximum number of grains that the $i$-th chicken can eat ($0 \le a_i \le 10^9$). The following $m$ lines contain three integers each $l_j$, $r_j$, and $c_j$ describing the $j$-th feeder ($1 \le l_j \le r_j \le n$, $0 \le c_j \le 10^9$).

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

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

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

출력

For each test print $n-1$ integers: the $i$-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 \le i$ and $r_j \ge i + 1$.

서브태스크

번호배점제한
15

$\sum{n} \le 100$, $\sum{m} \le 100$

210

$\sum{n} \le 500$, $\sum{m} \le 500$

325

$\sum{n} \le 1\,000$, $\sum{m} \le 1\,000$

410

$\sum{n} \le 2\,000$, $\sum{m} \le 100\,000$, $l_i \le l_{i+1}$, $r_i \le r_{i+1}$

520

$\sum{n} \le 500$, $\sum{m} \le 100\,000$

630

$\sum{n} \le 2\,000$, $\sum{m} \le 100\,000$

예제 입력 1

1
5 3
5 2 2 3 1
1 4 4
3 5 4
3 4 1

예제 출력 1

4 4 9 4

힌트

If you leave the feeders, from which chickens $1$ and $2$ 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 $3$ and $4$ 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 $4$ and $5$ can eat. Only the second feeder will remain. You can feed all grains from it.

채점 및 기타 정보

  • 예제는 채점하지 않는다.