GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Monday, 2 May 2022

Breaking the Wall Codeforces Solution | Codeforces Problem Solution 2022

E. Breaking the Wall
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 n sections, aligned in a row. The i-th section initially has durability ai. If durability of some section becomes 0 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 2 damage to the target section and 1 damage to adjacent sections. In other words, if the onager shoots at the section x, then the durability of the section x decreases by 2, and the durability of the sections x1 and x+1 (if they exist) decreases by 1 each.

Solution Click Below:-  CLICK HERE


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!

Input

The first line contains one integer n (2n2105) — the number of sections.

The second line contains the sequence of integers a1,a2,,an (1ai106), where ai is the initial durability of the i-th section.

Output

Print one integer — the minimum number of onager shots needed to break at least two sections of the wall.

Join Now for Solution:- 

                                                                        

No comments:

Post a Comment