占座的报应

TimeLimit:1000MS  MemoryLimit:258MB
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

The best students of high level quality universities usually grab front row seats for better listening to the lectures. 

However, since college students usually do not wake up early, the bad custom of going to the classroom one night earlier to take a seat with a book is prevalent.

To simplify the problem, suppose our seats are a straight line with coordinates 0 ~ n+1 expanded. 

In the night before the early eight, the moon is dark and windy, the air is only cold winter wind in the whistling, before and after there are n students, 

sneaking to the classroom, where the ith student with his book to occupy the coordinates of xi's position, because sitting on the edge of the most can

 not see the board clearly, so they will only take up the middle of the position of the 1 ~ n. 【The night is too too dark, so the students who take up the 

position of the position of the position of the students to see the position of the things, so there could be more than one placeholder book in one spot】. 


The next morning, in order to go to the front row of the lucid not confused at 6:00 a.m. out of bed, rushed to the classroom to see an empty, but full of books classroom, 

the front row! NO! Position up!!! The warm winter sun is so stinging and cold! She was so angry that she wanted to give a lesson to these bad occupation behavior. 

Xilibala intended to let the books occupy as little as possible, but not too obvious, for the position of xi occupation book, Xilibalacan move it to xi-1 or xi +1 position, 

or can also be retained in the position of xi, in order not to be detected, each book Xilibala only moved once! Multiple books in the same position can be placed in different 

positions,e.g., 3 books in position xi = 3 can be placed in positions 2, 3, 4 respectively.

 

We stipulate that for all placeholder books at positions 1 <= xi <= n, Clearly Not Confused can place the placeholder book at positions with coordinates 0 and n+1 

(if the placeholder book is at 1 or n respectively).

 

For example, the initial position of the placeholder is x=[1,2,4,4]. The final position can be [1,3,3,4], [0,2,3,3], [2,2,5,5], and so on....


Xilibala  wants you to help her figure out what is the minimum number of space occupied by these n placeholder books through her series of optimal magic operation?

Input

Enter a number n, indicating that there are n students to place books in the evening; 

Enter n numbers in the second line, x1,x2... .. xn ( 1<=xi<=n ) which position is occupied by n students' books.

Output

Figure out what is the minimum number of space occupied by these n placeholder books through her series of optimal magic operation?


SampleInput
2
1 2
SampleOutput
1
Submit
题目统计信息详细
总AC数4
通过人数4
尝试人数4
总提交量7
AC率57.14%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签
出处
作者

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: