#P16286. [蓝桥杯 2026 省 Python A 组] 电压调度

[蓝桥杯 2026 省 Python A 组] 电压调度

Problem Description

A scheduling center is responsible for voltage scheduling for NN parallel power transmission cables in a city. These cables are numbered from 11 to NN from left to right. Initially, the output voltage of all cables is 00 kV.

To meet the electricity demand of different areas, cable ii must finally be stabilized at voltage viv_i 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 [L,R][L, R] (1≤L≤R≤N1 \leq L \leq R \leq N), and increase the output voltage of all cables in this interval by 11 kV at the same time.

Given the target voltage sequence v1,v2,⋯ ,vNv_1, v_2, \cdots, v_N, 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 NN, indicating the number of power transmission cables.

The second line contains NN integers v1,v2,⋯ ,vNv_1, v_2, \cdots, v_N, where viv_i indicates the target voltage (in kV) that the ii-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 30%30\% of the testdata, 1≤N≤1031 \leq N \leq 10^3.

For 100%100\% of the testdata, 1≤N≤1051 \leq N \leq 10^5, 0≤vi≤1090 \leq v_i \leq 10^9.

Translated by ChatGPT 5