Codeforces Round 1048 (Div. 2)
B
Cake Collection
Codeforces
800
原题
← AC →
翻译中…

Maple wants to bake some cakes for Chocola and Vanilla.

翻译中…

One day, she discovers $n$ magical cake ovens. The $i$-th oven bakes $a_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 $m$ seconds.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 10^5$, $1\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 $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \le 10^5$) — the number of cakes the $i$-th oven bakes every second.

翻译中…

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

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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

翻译中…
  1. At the end of the first second, the ovens contain $1$, $2$, and $3$ cakes respectively. Maple teleports to oven $3$ and collects all $3$ cakes. Oven $3$ now has $0$ cakes remaining.
  2. At the end of the second second, the ovens contain $2$, $4$, and $3$ cakes respectively. Maple teleports to oven $1$ and collects all $2$ cakes. Oven $1$ now has $0$ cakes remaining.
  3. At the end of the third second, the ovens contain $1$, $6$, and $6$ cakes respectively. Maple teleports to oven $2$ and collects all $6$ cakes. Oven $2$ now has $0$ cakes remaining.
  4. At the end of the fourth second, the ovens contain $2$, $2$, and $9$ cakes respectively. Maple teleports to oven $3$ and collects all $9$ cakes. Oven $3$ now has $0$ cakes remaining.
翻译中…

In total, Maple collects $3+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 $1$, $2$, and $3$ cakes respectively. Maple teleports to oven $2$ and collects all $2$ cakes. Oven $2$ now has $0$ cakes remaining.
  2. At the end of the second second, the ovens contain $2$, $2$, and $6$ cakes respectively. Maple teleports to oven $3$ and collects all $6$ cakes. Oven $3$ now has $0$ cakes remaining.
翻译中…

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

翻译中…

样例

Input #1
3
3 4
1 2 3
3 2
1 2 3
1 1000
100000
Output #1
20
8
100000000
InputCopy OutputCopy
题目信息
题号
2139B
时间限制
1 s
内存限制
512 MB
标签
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。