QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#13237. Building Construction

Estadísticas

Little H is an architect who has received a task: to build a row of buildings according to a blueprint. The blueprint provides $n$ non-negative integers from left to right. For the $i$-th number $h_i$, it indicates that the height of the building constructed at position $i$ must not be less than $h_i$.

Little H's method of building is quite special. At any moment, he can always increase the heights of two adjacent buildings by 1 unit and 2 units, respectively. Specifically, for any $i$ ($1 \le i < n$), at each moment, he can choose one of the following two construction methods:

  1. Increase the height of the building at position $i$ by 2, and increase the height of the building at position $i+1$ by 1.
  2. Increase the height of the building at position $i$ by 1, and increase the height of the building at position $i+1$ by 2.

Little H wants to know the minimum time required to build this row of buildings such that they satisfy the requirements of the blueprint.

Input

The first line contains an integer $n$. The second line contains $n$ integers, $h_1, h_2, \dots, h_n$.

Output

A single line containing the answer, representing the minimum time required.

Examples

Input 1

4
2 1 1 2

Output 1

2

Note 1

Initially, the heights of the four buildings are 0 0 0 0. Little H needs at least the following two construction steps: 1. Increase the heights at positions 1 and 2 by 2 and 1, respectively; the heights become 2 1 0 0. 2. Increase the heights at positions 3 and 4 by 1 and 2, respectively; the heights become 2 1 1 2.

Input 2

13
12 13 9 8 3 21 7 10 1 1 8 1 1

Output 2

35

Subtasks

Let $h_{max} = \max\{h_1, h_2, \dots, h_n\}$.

Test Case ID $n$ $h_{max}$ Test Case ID $n$ $h_{max}$
1 $\le 3$ 11
2 $\le 5$ 12 $\le 10^3$
3 $\le 7$ 13
4 $\le 9$ 14
5 $\le 13$ 15
6 $\le 30$ 16
7 $\le 300$ 17 $\le 10^6$
8 18
9 19
10 20

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.