#P7730. [JDWOI-1] 蜀道难
[JDWOI-1] 蜀道难
Description
Little K and Little M also simulated the difficulty of the Shu roads. In this Shu Road Is Hard setting, there are mountains, and the height of the -th mountain is . Little K and Little M have types of magic. Each time they use a type of magic, they can increase or decrease the heights of a consecutive segment of mountains by , and it costs stamina points.
Now, Little K and Little M want the heights of the 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 , representing the number of mountains and the number of magic types.
The second line contains integers , representing the heights of the mountains.
The next lines each contain one character and three integers , describing one type of magic (if is , it means increasing; if is , it means decreasing).
Output Format
Output one integer, representing the minimum stamina cost.
If there is no solution, output .
3 3
1 3 2
- 1 10
- 2 3
+ 1 1
1
Hint
Sample Explanation
Use stamina point to increase the third mountain by .
Constraints
- For of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For all testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号