CF1119E.Pavel and Triangles

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

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, ..., an−1a_{n-1} sticks of length 2n−12^{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.

帕维尔有若干根长度为 2 的幂次的木棍。

他有 a0a_0 根长度为 20=12^0 = 1 的木棍,a1a_1 根长度为 21=22^1 = 2 的木棍,……,an−1a_{n-1} 根长度为 2n−12^{n-1} 的木棍。

帕维尔希望用这些木棍拼出尽可能多的三角形。每个三角形必须具有严格正的面积,且每根木棍至多被使用一次。

不允许折断木棍,且每个三角形必须恰好由三根木棍组成。

求最多能拼出多少个三角形。

输入格式

The first line contains a single integer nn (1≤n≤300 0001 \leq n \leq 300\,000) — the number of different lengths of sticks.

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

第一行包含一个整数 nn(1≤n≤300 0001 \leq n \leq 300\,000)—— 表示不同长度的木棍种类数。

第二行包含 nn 个整数 a0a_0, a1a_1, ..., an−1a_{n-1}(1≤ai≤1091 \leq a_i \leq 10^9),其中 aia_i 表示长度为 2i2^i 的木棍的数量。

输出格式

Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.

输出一个整数——Pavel 能够组成的非退化三角形的最大可能数量。

输入输出样例

  • 输入#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).

在第一个例子中,帕维尔可以(例如)构造如下三角形集合(列出各三角形的边长):(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)。

在第二个例子中,帕维尔无法构造出任何一个三角形。

在第三个例子中,帕维尔可以(例如)构造如下三角形集合(列出各三角形的边长):(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)。

输入解题思路,AI测评打分。不知道怎么写?

首页