howell

I just follow my heart ! ! !

Kirill the Gardener 3 URAL - 2072

2072. Kirill the Gardener 3

Time limit: 2.0 second
Memory limit: 64 MB
Kirill the gardener has got a new task. He has to water the flowers growing on the huge flowerbed! It should be mentioned that the bed is very long and narrow at the same time. So from bird’s-eye view (and Kirill growth too) it looks like a straight line, where n points-flowers are located at regular intervals. For this job Kirill has a watering pot of infinite volume and smartwatch that shows moisture content of each flower before watering. The watering takes too much time, so the most dried flowers can die, which is unacceptable. So Kirill decided to water the flowers in order of their non-decreasing dryness. On the other hand, he wants to finish the watering as soon as possible, because there are a lot of other interesting things.
Assume that watering of one flower and walking between two neighbor flowers takes Kirill one minute. Can you figure out the time in which the young gardener will complete his job if he acts optimally? Initially Kirill stands near the leftmost flower.

Input

The first line contains an integer n (1 ≤ n ≤ 105) — it’s amount of flowers in the flowerbed. The second line contains n integers separated by spaces — it‘s moisture content of flowers given in order of their positions in the flowerbed from left to right. Moisture content is an integer from 1 up to 109 (including both).

Output

In the only line print an integer — the minimal time in which Kirill would complete watering.

Sample

inputoutput
6
3 2 5 6 2 5
21

Notes

There is one of the possible ways to finish up in 21 minutes in the example:
  1. Go from the 1st to the 5th flower (4 minutes)
  2. Water the 5th flower (1 minute)
  3. Go from the 5th to the 2nd flower (3 minutes)
  4. Water the 2nd flower (1 minute)
  5. Go from the 2nd to the 1st flower (1 minute)
  6. Water the 1st flower (1 minute)
  7. Go from the 1st flower to the 3rd flower (2 minutes)
  8. Water the 3rd flower (1 minute)
  9. Go from the 3rd flower to the 6th flower (3 minutes)
  10. Water the 6th flower (1 minute)
  11. Go from the 6th flower to the 4th flower (2 minutes)
  12. Water the 4th flower (1 minute)
Problem Author: Ilya Kuchumov
Problem Source: Ural Regional School Programming Contest 2015
阅读更多
版权声明: https://blog.csdn.net/weixin_39792252/article/details/80345744
想对作者说点什么? 我来说一句

Kirill the Gardener 3 C++程序

2015年11月08日 1KB 下载

Ural 2072

DP

JalexDooo JalexDooo

2016-08-22 19:55:31

阅读数:280

没有更多推荐了,返回首页

不良信息举报

Kirill the Gardener 3 URAL - 2072

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭