#P16286. [蓝桥杯 2026 省 Python A 组] 电压调度
[蓝桥杯 2026 省 Python A 组] 电压调度
Problem Description
A scheduling center is responsible for voltage scheduling for parallel power transmission cables in a city. These cables are numbered from to from left to right. Initially, the output voltage of all cables is kV.
To meet the electricity demand of different areas, cable must finally be stabilized at voltage kV. To achieve this, the scheduling center is equipped with an “interval voltage boosting device”: it can be activated once per day. Each time, an engineer may choose any continuous interval (), and increase the output voltage of all cables in this interval by kV at the same time.
Given the target voltage sequence , compute the minimum number of days needed to make the voltage of each cable reach exactly its corresponding target value.
Input Format
The first line contains an integer , indicating the number of power transmission cables.
The second line contains integers , where indicates the target voltage (in kV) that the -th cable needs to reach.
Output Format
Output one integer in one line, indicating the minimum number of days required to make the voltages of all cables reach exactly the target values.
4
1 2 1 2
3
Hint
Constraints
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5