QOJ.ac

QOJ

時間限制: 8 s 記憶體限制: 1024 MB 總分: 100 难度: [顯示]

#5076. 庞教授与蚂蚁

统计

在庞教授的大房子附近,有一个蚂蚁群,它们有 $m$ 只蚂蚁,生活在地下一个有 $n$ 个洞的洞穴中。它们为了寻找食物而从洞中爬出来。那么食物在哪里呢?应该在庞教授的大冰箱里。蚂蚁们想要从大冰箱里偷走食物。

具体来说,对于一只蚂蚁,它需要 1 秒钟通过任意一个洞离开洞穴,并需要 1 秒钟通过任意一个洞进入洞穴。不同的洞位置不同。第 $i$ 个洞到冰箱的距离为 $a_i$。因此,通过第 $i$ 个洞离开洞穴后,蚂蚁需要 $a_i$ 秒到达冰箱。从冰箱偷到食物后,蚂蚁需要 $a_i$ 秒回到第 $i$ 个洞。由于蚂蚁非常熟练,偷食物不需要时间。

每只蚂蚁都会离开洞穴去冰箱偷东西,并在偷完后返回(进入)洞穴。每只蚂蚁必须恰好离开洞穴一次,然后返回洞穴。一只蚂蚁可以任意选择一个洞离开,也可以任意选择一个洞进入,这两个洞不必是同一个。对于任何一个洞,在任何一秒钟内,最多只能有一只蚂蚁通过它离开或进入洞穴。在同一秒钟内,不能有一只蚂蚁通过同一个洞离开洞穴,而另一只蚂蚁通过该洞进入洞穴。由于这种容量限制,一些蚂蚁在离开洞穴之前和/或在偷完食物返回洞穴之前可能需要等待。

作为庞教授的好朋友,你需要计算蚂蚁完成目标所需的最小时间成本,并给庞教授设个圈套,让蚂蚁们能在不被庞教授发现的情况下偷走食物。时间成本定义为至少有一只蚂蚁不在洞穴中的总时长。当一只蚂蚁通过某个洞进入或离开洞穴时,它不在洞穴中。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。

对于每个测试用例,第一行包含两个整数 $n, m$ ($1 \le n \le 10^5, 1 \le m \le 10^{14}$),分别表示洞的数量和蚂蚁的数量。第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$),表示从第 $i$ 个洞到达冰箱所需的时间。

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

输出格式

对于每个测试用例,输出一行,包含一个整数,表示以秒为单位的最小时间成本。

样例

输入格式 1

3
2 4
1 2
3 10
1 2 3
5 1
1 2 3 4 5

输出格式 1

6
9
4

说明

在第三个测试用例中,蚂蚁通过第一个洞离开和进入洞穴需要 2 秒。蚂蚁移动到冰箱并返回洞口也需要 2 秒。

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.