QOJ.ac

QOJ

実行時間制限: 6 s メモリ制限: 2048 MB 満点: 100 難易度: [表示] ハック可能 ✓

#18204. 木棒 2

統計

小蓝鱼(Little Cyan Fish)有 $n$ 根木棍,其中第 $i$ 根木棍的长度为 $2^{a_i}$。

他想把所有的木棍从左到右依次放置在数轴上,且起点不早于位置 $m$。

正式地,给定一个序列 $a_1, a_2, \dots, a_n$ 和一个起始边界 $m$,设 $l_i$ 和 $r_i$ 分别表示第 $i$ 个放置的木棍的左端点和右端点。如果满足以下所有条件,则该放置方案是合法的:

  • $l_1 \ge m$;
  • 对于每个 $1 \le i \le n$,有 $r_i = l_i + 2^{a_i}$;
  • 对于每个 $1 \le i \le n$,$l_i$ 必须能被 $2^{a_i}$ 整除;
  • 对于每个 $1 \le i < n$,有 $r_i \le l_{i+1}$。

对于一个固定的排列 $a_1, a_2, \dots, a_n$,定义 $f(a)$ 为所有合法放置方案中 $r_n$ 的最小可能值。

在放置木棍之前,小蓝鱼可以按他希望的任意顺序重新排列 $a_1, a_2, \dots, a_n$。求在所有可能的重新排列中,$f(a)$ 的最大可能值。

输入格式

每个输入文件包含多个测试用例。输入的第一行包含一个整数 $T$ ($1 \le T$),表示测试用例的数量。

对于每个测试用例,第一行包含两个整数 $n$ 和 $m$ ($1 \le n \le 2 \times 10^5$, $0 \le m < 2^{100}$)。第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i < 100$)。

保证所有测试用例中 $n$ 的总和不超过 $2 \times 10^5$。

输出格式

对于每个测试用例,输出一个整数,表示重新排列 $a_1, a_2, \dots, a_n$ 后 $f(a)$ 的最大可能值。

样例

输入样例 1

2
3 0
1 2 3
5 14
0 2 2 3 3

输出样例 1

20
52

说明

在第一个样例中,小蓝鱼可以将木棍重新排列,使其长度依次为 $2^1, 2^3, 2^2$。将它们放置在区间 $[0, 2]$、$[8, 16]$ 和 $[16, 20]$ 是合法的,因此该排列的 $f(a) = 20$。这是最大可能的值。

在第二个样例中,一种最优的重新排列方式使木棍长度依次为 $4, 8, 1, 8, 4$。下图展示了一个结束于 $52$ 的合法放置方案,因此答案为 $52$。

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.