309408: CF1674E. Breaking the Wall
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Breaking the Wall
题意翻译
现在有一个正整数序列 $a$ , 你可以选择一个位置 $i$ ,进行一次操作:将 $a_i$ 减去 $2$ ,将 $a_{i-1}$(如果存在)减去 $1$ ,将 $a_{i+1}$(如果存在)减去 $1$,问至少要多少次操作可以使数列中至少出现两个非正整数。 Translated by CmsMartin题目描述
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 $ a_i $ . 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 $ x - 1 $ and $ x + 1 $ (if they exist) decreases by $ 1 $ 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 $ n $ ( $ 2 \le n \le 2 \cdot 10^5 $ ) — the number of sections. The second line contains the sequence of integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 10^6 $ ), where $ a_i $ is the initial durability of the $ i $ -th section.
输出格式
Print one integer — the minimum number of onager shots needed to break at least two sections of the wall.
输入输出样例
输入样例 #1
5
20 10 30 10 20
输出样例 #1
10
输入样例 #2
3
1 8 1
输出样例 #2
1
输入样例 #3
6
7 6 6 8 5 8
输出样例 #3
4
输入样例 #4
6
14 3 8 10 15 4
输出样例 #4
4
输入样例 #5
4
1 100 100 1
输出样例 #5
2
输入样例 #6
3
40 10 10
输出样例 #6
7