CF1119E.Pavel and Triangles

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Pavel has several sticks with lengths equal to powers of two.

He has a0a_0 sticks of length 20=12^0 = 1 , a1a_1 sticks of length 21=22^1 = 2 , ..., an1a_{n-1} sticks of length 2n12^{n-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 nn ( 1n3000001 \leq n \leq 300\,000 ) — the number of different lengths of sticks.

The second line contains nn integers a0a_0 , a1a_1 , ..., an1a_{n-1} ( 1ai1091 \leq a_i \leq 10^9 ), where aia_i is the number of sticks with the length equal to 2i2^i .

输出格式

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)(2^0, 2^4, 2^4) , (21,23,23)(2^1, 2^3, 2^3) , (21,22,22)(2^1, 2^2, 2^2) .

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)(2^0, 2^0, 2^0) , (21,21,21)(2^1, 2^1, 2^1) , (22,22,22)(2^2, 2^2, 2^2) .

首页