CF2139B.Cake Collection

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Cake Collection

Maple wants to bake some cakes for Chocola and Vanilla.

One day, she discovers nn magical cake ovens. The ii-th oven bakes aia_i cakes every second. The cakes remain in their respective ovens until they are collected.

At the end of each second, she may teleport to any oven (including the one she is currently at) and collect all the cakes that have accumulated in that oven up to that point.

Your task is to determine the maximum number of cakes Maple can collect in mm seconds.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \le t \le 1000). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1n1051 \leq n \leq 10^5, 1m1081\leq m\leq 10^8) — the number of magical ovens and the number of seconds during which Maple will collect cakes.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1051 \leq a_i \le 10^5) — the number of cakes the ii-th oven bakes every second.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output a single integer representing the maximum number of cakes Maple can collect in mm seconds.

Note

For the first test case, one optimal solution is as follows:

  1. At the end of the first second, the ovens contain 11, 22, and 33 cakes respectively. Maple teleports to oven 33 and collects all 33 cakes. Oven 33 now has 00 cakes remaining.
  2. At the end of the second second, the ovens contain 22, 44, and 33 cakes respectively. Maple teleports to oven 11 and collects all 22 cakes. Oven 11 now has 00 cakes remaining.
  3. At the end of the third second, the ovens contain 11, 66, and 66 cakes respectively. Maple teleports to oven 22 and collects all 66 cakes. Oven 22 now has 00 cakes remaining.
  4. At the end of the fourth second, the ovens contain 22, 22, and 99 cakes respectively. Maple teleports to oven 33 and collects all 99 cakes. Oven 33 now has 00 cakes remaining.

In total, Maple collects 3+2+6+9=203+2+6+9=20 cakes.

For the second test case, one optimal solution is as follows:

  1. At the end of the first second, the ovens contain 11, 22, and 33 cakes respectively. Maple teleports to oven 22 and collects all 22 cakes. Oven 22 now has 00 cakes remaining.
  2. At the end of the second second, the ovens contain 22, 22, and 66 cakes respectively. Maple teleports to oven 33 and collects all 66 cakes. Oven 33 now has 00 cakes remaining.

In total, Maple collects 2+6=82+6=8 cakes.

Samples

3
3 4
1 2 3
3 2
1 2 3
1 1000
100000
20
8
100000000

在线编程 IDE

建议全屏模式获得最佳体验