CF1901D.Yet Another Monster Fight

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya is a sorcerer that fights monsters. Again. There are nn monsters standing in a row, the amount of health points of the ii -th monster is aia_i .

Vasya is a very powerful sorcerer who knows many overpowered spells. In this fight, he decided to use a chain lightning spell to defeat all the monsters. Let's see how this spell works.

Firstly, Vasya chooses an index ii of some monster ( 1in1 \le i \le n ) and the initial power of the spell xx . Then the spell hits monsters exactly nn times, one hit per monster. The first target of the spell is always the monster ii . For every target except for the first one, the chain lightning will choose a random monster who was not hit by the spell and is adjacent to one of the monsters that already was hit. So, each monster will be hit exactly once. The first monster hit by the spell receives xx damage, the second monster receives (x1)(x-1) damage, the third receives (x2)(x-2) damage, and so on.

Vasya wants to show how powerful he is, so he wants to kill all the monsters with a single chain lightning spell. The monster is considered dead if the damage he received is not less than the amount of its health points. On the other hand, Vasya wants to show he doesn't care that much, so he wants to choose the minimum initial power of the spell xx such that it kills all monsters, no matter which monster (among those who can get hit) gets hit on each step.

Of course, Vasya is a sorcerer, but the amount of calculations required to determine the optimal spell setup is way above his possibilities, so you have to help him find the minimum spell power required to kill all the monsters.

Note that Vasya chooses the initial target and the power of the spell, other things should be considered random and Vasya wants to kill all the monsters even in the worst possible scenario.

输入格式

The first line of the input contains one integer nn ( 1n31051 \le n \le 3 \cdot 10^5 ) — the number of monsters.

The second line of the input contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1091 \le a_i \le 10^9 ), where aia_i is the amount of health points of the ii -th monster.

输出格式

Print one integer — the minimum spell power required to kill all the monsters if Vasya chooses the first target optimally, and the order of spell hits can be any possible within the given rules.

输入输出样例

  • 输入#1

    6
    2 1 5 6 4 3

    输出#1

    8
  • 输入#2

    5
    4 4 4 4 4

    输出#2

    8
  • 输入#3

    2
    1 1000000000

    输出#3

    1000000000
首页