ユニークビジョンプログラミングコンテスト2026 夏(AtCoder Regular Contest 226)
B
二进制装箱
Bin-ary Packing
AtCoder
⌀ 1207
原题
← AC →

二进制装箱AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There are $N$ bags numbered $1,2,\dots,N$. Also, for each $i=0,1,\dots,M-1$, there are $A_i$ packages of weight $2^i$. There are $A_0+A_1+\dots+A_{M-1}$ packages in total.

有 $N$ 个袋子,编号为 $1,2,\dots,N$。此外,对于每个 $i=0,1,\dots,M-1$,都有 $A_i$ 个重量为 $2^i$ 的包裹。包裹总数为 $A_0+A_1+\dots+A_{M-1}$。AI (CI翻译)

Every package is put into exactly one of the bags. Some bags may remain empty.

每个包裹必须恰好放入一个袋子中。部分袋子可以为空。AI (CI翻译)

For each bag, the sum of the weights of all packages in that bag is called the weight of the bag.

对于每个袋子,其中所有包裹的重量之和称为该袋子的重量。AI (CI翻译)

Find the minimum possible value of the maximum of the weights of the $N$ bags.

求 $N$ 个袋子中重量的最大值可能达到的最小值。AI (CI翻译)

You are given $T$ test cases; solve each of them.

给定 $T$ 组测试用例,请分别求解。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le T \le 10^5$
  • $1 \le N \le 10^6$
  • $1 \le M \le 40$
  • $0 \le A_i \le 10^6$
  • The sum of $M$ over all test cases is at most $2 \times 10^5$.
  • All input values are integers.
  • $1 \le T \le 10^5$
  • $1 \le N \le 10^6$
  • $1 \le M \le 40$
  • $0 \le A_i \le 10^6$
  • 所有测试用例中 $M$ 的总和不超过 $2 \times 10^5$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
AI (CI翻译)

Each test case is given in the following format:

每组测试用例按以下格式给出:AI (CI翻译)

N M
A_0 A_1 \ldots A_{M-1}

N M
A_0 A_1 \ldots A_{M-1}
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines.

输出 $T$ 行。AI (CI翻译)

The $i$-th line should contain the minimum possible value of the maximum of the weights of the bags for the $i$-th test case.

第 $i$ 行应包含第 $i$ 组测试用例中,$N$ 个袋子的重量最大值可能达到的最小值。AI (CI翻译)

样例

Input #1
4
2 3
3 2 1
1000000 1
0
1 40
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
188075 10
858153 791486 630853 157728 813993 50047 286602 459270 597406 907405
Output #1
6
0
549755813888
3805
In the first test case, there are $3,2,1$ packages of weight $1,2,4$, respectively. For example, let the weights of the packages put into bags $1,2$ be $(4,1,1),(2,2,1)$, respectively. Then, the weights of bags $1,2$ are $6,5$, respectively, and the maximum of these is $6$. It is impossible to make the maximum of the weights of the bags $5$ or less.
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。