CF1119E.Pavel and Triangles
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Pavel has several sticks with lengths equal to powers of two.
He has a0 sticks of length 20=1 , a1 sticks of length 21=2 , ..., an−1 sticks of length 2n−1 .
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
输入格式
The first line contains a single integer n ( 1≤n≤300000 ) — the number of different lengths of sticks.
The second line contains n integers a0 , a1 , ..., an−1 ( 1≤ai≤109 ), where ai is the number of sticks with the length equal to 2i .
输出格式
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
输入输出样例
输入#1
5 1 2 2 2 2
输出#1
3
输入#2
3 1 1 1
输出#2
0
输入#3
3 3 3 3
输出#3
3
说明/提示
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (20,24,24) , (21,23,23) , (21,22,22) .
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (20,20,20) , (21,21,21) , (22,22,22) .