Good Bye 2024: 2025 is NEAR
H
Delicate Anti-monotonous Operations
Codeforces
3500
原题
← GI1 →
翻译中…

I shall be looking for you who would be out of Existence.— HyuN, Disorder

翻译中…

There are always many repetitive tasks in life. Iris always dislikes them, so she refuses to repeat them. However, time cannot be turned back; we only have to move forward.

翻译中…

Formally, Iris has an integer sequence $a_1, a_2, \ldots, a_n$, where each number in the sequence is between $1$ and $w$, inclusive. It is guaranteed that $w \geq 2$.

翻译中…

Iris defines an operation as selecting two numbers $a_i, a_{i+1}$ satisfying $a_i = a_{i+1}$, and then changing them to two arbitrary integers within the range $[1, w]$. Iris does not like equality, so she must guarantee that $a_i \neq a_{i+1}$ after the operation. Two identical pairs $a_i, a_{i+1}$ can be selected multiple times.

翻译中…

Iris wants to know the maximum possible sum of all elements of $a$ after several (possible, zero) operations, as well as the minimum number of operations required to achieve this maximum value.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $w$ ($1 \leq n \leq 2\cdot 10^5$, $2 \leq w \leq 10^8$) — the length of the array, and the maximum allowed value of the elements.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq w$) — the elements in the array.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, output two integers — the maximum possible sum of all elements of $a$ and the minimum number of operations required, respectively.

翻译中…

Note

翻译中…

In the first test case, no operation can be performed so the answers are $\sum a_i = 15$ and $0$, respectively.

翻译中…

In the second test case, the operations can be performed as follows:

翻译中…

$$[3, 1, 2, 3, 4, \underline{1, 1}] \rightarrow [3, 1, 2, 3, \underline{4, 4}, 5] \rightarrow [3, 1, 2, \underline{3, 3}, 5, 5] \rightarrow [3, 1, \underline{2, 2}, 5, 5, 5] \rightarrow [3, \underline{1, 1}, 5, 5, 5, 5] \rightarrow [\underline{3, 3}, 5, 5, 5, 5, 5] \rightarrow [4, 5, 5, 5, 5, 5, 5]$$

翻译中…

It can be shown this is optimal, so we should output $\sum a_i = 34$ and the number of operations, $6$, respectively.

翻译中…

样例

Input #1
2
5 8
1 2 3 4 5
7 5
3 1 2 3 4 1 1
Output #1
15 0
34 6
InputCopy OutputCopy
题目信息
题号
2053H
时间限制
2 s
内存限制
512 MB
标签
构造
模拟

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