AT_arc226_b.Bin-ary Packing

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are NN bags numbered 1,2,…,N1,2,\dots,N. Also, for each i=0,1,…,M−1i=0,1,\dots,M-1, there are AiA_i packages of weight 2i2^i. There are A0+A1+⋯+AM−1A_0+A_1+\dots+A_{M-1} packages in total.

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

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

Find the minimum possible value of the maximum of the weights of the NN bags.

You are given TT test cases; solve each of them.

有编号为 1,2,…,N1,2,\dots,N 的 NN 个袋子。此外,对每个 i=0,1,…,M−1i=0,1,\dots,M-1,存在 AiA_i 个重量为 2i2^i 的包裹。总共共有 A0+A1+⋯+AM−1A_0+A_1+\dots+A_{M-1} 个包裹。

每个包裹恰好放入一个袋子中。某些袋子可能为空。

对于每个袋子,其中所有包裹的重量之和称为该袋子的重量。

求这 NN 个袋子的重量的最大值的最小可能值。

你将收到 TT 组测试数据;请分别求解每组数据。

输入格式

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

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN MM
A0A_0 A1A_1 …\ldots AM−1A_{M-1}

输入从标准输入给出,格式如下:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例的格式如下:

NN MM
A0A_0 A1A_1 …\ldots AM−1A_{M-1}

输出格式

Output TT lines.

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

输出 TT 行。

第 ii 行应包含第 ii 个测试用例中,各袋子重量的最大值的最小可能值。

输入输出样例

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

    输出#1

    6
    0
    549755813888
    3805

说明/提示

Sample 1 Explanation:
In the first test case, there are 3,2,13,2,1 packages of weight 1,2,41,2,4, respectively.

For example, let the weights of the packages put into bags 1,21,2 be (4,1,1),(2,2,1)(4,1,1),(2,2,1), respectively. Then, the weights of bags 1,21,2 are 6,56,5, respectively, and the maximum of these is 66.

It is impossible to make the maximum of the weights of the bags 55 or less.

Constraints

  • 1≤T≤1051 \le T \le 10^5
  • 1≤N≤1061 \le N \le 10^6
  • 1≤M≤401 \le M \le 40
  • 0≤Ai≤1060 \le A_i \le 10^6
  • The sum of MM over all test cases is at most 2×1052 \times 10^5.
  • All input values are integers.

样例 1 解释:
在第一个测试用例中,重量分别为 1,2,41,2,4 的包裹数量依次为 3,2,13,2,1。

例如,将重量为 (4,1,1)(4,1,1) 的包裹放入背包 11,将重量为 (2,2,1)(2,2,1) 的包裹放入背包 22。此时,背包 11 和背包 22 的总重量分别为 66 和 55,其最大值为 66。

无法使所有背包的总重量最大值不超过 55。

约束条件

  • 1≤T≤1051 \le T \le 10^5
  • 1≤N≤1061 \le N \le 10^6
  • 1≤M≤401 \le M \le 40
  • 0≤Ai≤1060 \le A_i \le 10^6
  • 所有测试用例中 MM 的总和不超过 2×1052 \times 10^5。
  • 所有输入值均为整数。

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

首页