QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 64 MB Puntuación total: 10

#11028. 对数辣椒 [B]

Estadísticas

Byteland 最畅销的蔬菜是“对数辣椒”。正如这种伟大蔬菜的名字所暗示的那样,每个辣椒的重量都是 2 的幂。最轻的辣椒重 $2^{0}$ 克,最重的辣椒重 $2^{k}$ 克。

Byteland 的居民不喜欢购买切开的辣椒,因此销售商被迫只能整块出售。此外,Byteland 人非常严谨,他们无法容忍销售商无法凑出他们想要购买的精确重量的情况。这给 Byteland 的所有销售商带来了压力——甚至已经出现了失眠的病例。你的一位拥有菜园的朋友请求你编写一个程序来帮助这些销售商。

编写一个程序,完成以下任务:

  • 从标准输入读取当前辣椒库存的描述;
  • 确定无法在不切割任何辣椒的情况下称出的最小重量;
  • 将结果写入标准输出。

输入格式

输入的第一行包含一个整数 $k$ ($1 \le k \le 10$),表示可用辣椒的重量集合为 $2^0, 2^1, \ldots, 2^k$。第二行包含 $k + 1$ 个不超过 1000 的正整数 $p_{0}, p_{1}, \ldots, p_{k}$,由空格分隔,表示当前库存:$p_{0}$ 个重量为 1 克的辣椒,$p_{1}$ 个重量为 2 克的辣椒,以此类推,$p_{k}$ 个重量为 $2^{k}$ 克的辣椒。

输出格式

输出的第一行且仅包含一行,为一个正整数 $x$,表示无法在不切割任何辣椒的情况下称出的最小重量。

样例

输入 1

2
2 1 1

输出 1

9

说明

库存中的辣椒可以称出 1 到 8 之间的所有重量:1 = 1, 2 = 1 + 1, 3 = 1 + 2, 4 = 4, 5 = 1 + 4, 6 = 1 + 1 + 4, 7 = 1 + 2 + 4, 8 = 1 + 1 + 2 + 4。数值 9 无法称出,因此它是该样例的答案。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.