#P3337. [ZJOI2013] 防守战线

[ZJOI2013] 防守战线

Description

The frontline can be viewed as a sequence of length nn. We need to build towers on this sequence to defend against enemy troops. Building a tower at position ii costs CiC_i, and any number of towers can be built at the same position, with costs added together. There are mm intervals [L1,R1],[L2,R2],,[Lm,Rm][L_1, R_1], [L_2, R_2], \cdots, [L_m, R_m], and within the ii-th interval, at least DiD_i towers must be built. Find the minimum cost.

Input Format

The first line contains two numbers n,mn, m.

The next line contains nn numbers, describing the CC array.

The next mm lines each contain three numbers Li,Ri,DiL_i, R_i, D_i, describing an interval.

Output Format

Output a single line with one number: the minimum cost.

5 3
1 5 6 3 4
2 3 1
1 5 4
3 5 2
11

Hint

Sample explanation:

Build 22 towers at position 11, one tower at position 33, and one tower at position 44. The cost is 1×2+6+3=111\times 2+6+3=11.

Constraints:

  • For 20%20\% of the testdata, n20n \le 20, m20m \le 20.
  • For 50%50\% of the testdata (including the above), all DiD_i are 11.
  • For 70%70\% of the testdata (including the above), n100n \le 100, m1000m \le 1000.
  • For 100%100\% of the testdata, n1000n \le 1000, m10000m \le 10000, 1LiRin1 \le L_i \le R_i \le n, and all other values are 10000\le 10000.

Translated by ChatGPT 5