CF2053H.Delicate Anti-monotonous Operations
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 a1,a2,…,an, where each number in the sequence is between 1 and w, inclusive. It is guaranteed that w≥2.
Iris defines an operation as selecting two numbers ai,ai+1 satisfying ai=ai+1, and then changing them to two arbitrary integers within the range [1,w]. Iris does not like equality, so she must guarantee that ai=ai+1 after the operation. Two identical pairs ai,ai+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.
我将寻找那已不复存在的你。
—— HyuN,《Disorder》(feat. Yuri),K-SOUNDS STUDIO
生活中总有许多重复的任务。Iris 一向讨厌重复,因此她拒绝重复执行它们。然而,时光无法倒流;我们只能向前迈进。
形式化地,Iris 拥有一个整数序列 a1,a2,…,an,其中序列中每个数均在 [1,w] 范围内(含端点)。题目保证 w≥2。
Iris 将一次操作定义为:选取两个相邻元素 ai,ai+1,满足 ai=ai+1,然后将它们同时替换为 [1,w] 范围内的任意两个整数。由于 Iris 不喜欢相等,因此操作后必须保证 ai=ai+1。相同的相邻对 ai,ai+1 可被多次选取。
Iris 想知道:经过若干次(可能为零次)操作后,序列 a 所有元素之和所能达到的最大值,以及达成该最大值所需的最少操作次数。
输入格式
Each test contains multiple test cases. The first line contains an integer t (1≤t≤105) — 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≤n≤2⋅105, 2≤w≤108) — the length of the array, and the maximum allowed value of the elements.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤w) — the elements in the array.
It is guaranteed that the sum of n over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤105)—— 测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 w(1≤n≤2⋅105,2≤w≤108)—— 数组的长度以及元素允许的最大值。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤w)—— 数组中的元素。
保证所有测试用例的 n 之和不超过 106。
输出格式
For each test case, output two integers — the maximum possible sum of all elements of a and the minimum number of operations required, respectively.
对于每个测试用例,输出两个整数——数组 a 所有元素之和的最大可能值,以及所需的最少操作次数。
输入输出样例
输入#1
2 5 8 1 2 3 4 5 7 5 3 1 2 3 4 1 1
输出#1
15 0 34 6
说明/提示
In the first test case, no operation can be performed so the answers are ∑ai=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 ∑ai=34 and the number of operations, 6, respectively.
在第一个测试用例中,无法执行任何操作,因此答案分别为 ∑ai=15 和 0。
在第二个测试用例中,操作可按如下方式进行:
\[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\]可以证明该方案是最优的,因此我们应分别输出 ∑ai=34 和操作次数 6。
输入解题思路,AI测评打分。不知道怎么写?