Breaking the Wall Codeforces Solution | Codeforces Problem Solution 2022
Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.
The wall consists of sections, aligned in a row. The -th section initially has durability . If durability of some section becomes or less, this section is considered broken.
To attack the opponent, Monocarp needs to break at least two sections of the wall (any two sections: possibly adjacent, possibly not). To do this, he plans to use an onager — a special siege weapon. The onager can be used to shoot any section of the wall; the shot deals damage to the target section and damage to adjacent sections. In other words, if the onager shoots at the section , then the durability of the section decreases by , and the durability of the sections and (if they exist) decreases by each.
Monocarp can shoot at any sections any number of times, he can even shoot at broken sections.
Monocarp wants to calculate the minimum number of onager shots needed to break at least two sections. Help him!
The first line contains one integer () — the number of sections.
The second line contains the sequence of integers (), where is the initial durability of the -th section.
No comments:
Post a Comment