#P7730. [JDWOI-1] 蜀道难

[JDWOI-1] 蜀道难

Background

Shu Road Is Hard, harder than climbing to the sky...

The reason the Shu roads are hard is that the mountain paths are rough and uneven.

Problem Description

Little K and Little M also simulated the difficulty of the Shu roads. In this Shu Road Is Hard setting, there are nn mountains, and the height of the ii-th mountain is hih_i. Little K and Little M have mm types of magic. Each time they use a type of magic, they can increase or decrease the heights of a consecutive segment of lil_i mountains by 11, and it costs cic_i stamina points.

Now, Little K and Little M want the heights of the nn mountains in Shu Road Is Hard to be non-decreasing, so that the road will no longer be hard. What is the minimum stamina cost?

Note: The height of any mountain can never be negative at any time.

Input Format

The first line contains two integers n,mn, m, representing the number of mountains and the number of magic types.

The second line contains nn integers hih_i, representing the heights of the mountains.

The next mm lines each contain one character and three integers wi,li,ciw_i, l_i, c_i, describing one type of magic (if wiw_i is ++, it means increasing; if wiw_i is -, it means decreasing).

Output Format

Output one integer, representing the minimum stamina cost.

If there is no solution, output 1-1.

3 3
1 3 2
- 1 10
- 2 3
+ 1 1
1

Hint

Sample Explanation

Use 11 stamina point to increase the third mountain by 11.

Constraints

  • For 10%10\% of the testdata, 1n,m101 \leq n, m \leq 10.
  • For another 30%30\% of the testdata, 1n,m201 \leq n, m \leq 20.
  • For another 10%10\% of the testdata, m=1m = 1.
  • For all testdata, 1n,m2001 \leq n, m \leq 200, 1lin1 \leq l_i \leq n, 1hi,ci1031 \leq h_i, c_i \leq 10^3.

Translated by ChatGPT 5