CF2154E.No Mind To Think

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array of positive integers aa of length nn and a positive integer kk, and you will play the following game with them:

  • At the start of the game, you will choose an odd integer xx (1≤x≤n1 \le x \le n).
  • Then do the following at most kk times (possibly none):
    • Select a subsequence of aa of length xx, then replace every value in the subsequence with the median∗^{\text{∗}} of that subsequence. More formally, pick xx integers i1,…,ixi_1,\ldots,i_x (1≤i1<i2<…<ix≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_x \le n). Then simultaneously do aida_{i_d}:= median([ai1,ai2,…,aix])\mathrm{median}([a_{i_1},a_{i_2},\ldots,a_{i_x}]) for all dd (1≤d≤x1 \le d \le x).

Note that the integer xx you choose cannot change between operations.

Determine the maximum value for the sum of aa obtainable after playing the game.

∗^{\text{∗}}The median of an array aa of length nn (written median(a)\mathrm{median}(a)) is the ⌊n+12⌋\left\lfloor\frac{n + 1}{2}\right\rfloor-th smallest element in aa, where ⌊x⌋\left\lfloor x \right\rfloor denotes the largest integer which is smaller than or equal to xx. For example, median([4,3,1,2,5])=3\mathrm{median}([4, 3, 1, 2, 5]) = 3 and median([4,3,5,3])=3\mathrm{median}([4, 3, 5, 3]) = 3.

给你一个长度为 nn 的正整数数组 aa 和一个正整数 kk,你将与它们进行如下游戏:

  • 游戏开始时,你需要选择一个奇数 xx(满足 1≤x≤n1 \le x \le n)。
  • 然后最多执行 kk 次(也可不执行)以下操作:
    • 从 aa 中选出一个长度为 xx 的子序列,并将该子序列中每个值都替换为该子序列的中位数∗^{\text{∗}}。更准确地说,选取 xx 个下标 i1,…,ixi_1,\ldots,i_x(满足 1≤i1<i2<…<ix≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_x \le n),然后对所有 dd(1≤d≤x1 \le d \le x)同时令 aid:=median([ai1,ai2,…,aix])a_{i_d} := \mathrm{median}([a_{i_1},a_{i_2},\ldots,a_{i_x}])。

注意:你在整个过程中选定的 xx 值不能更改。

求游戏结束后数组 aa 元素之和所能达到的最大值。

∗^{\text{∗}} 长度为 nn 的数组 aa 的中位数(记作 median(a)\mathrm{median}(a))定义为 aa 中第 ⌊n+12⌋\left\lfloor\frac{n + 1}{2}\right\rfloor 小的元素,其中 ⌊x⌋\left\lfloor x \right\rfloor 表示不超过 xx 的最大整数。例如,median([4,3,1,2,5])=3\mathrm{median}([4, 3, 1, 2, 5]) = 3,而 median([4,3,5,3])=3\mathrm{median}([4, 3, 5, 3]) = 3。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains integers nn and kk (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5, 1≤k≤2⋅1051 \le k \le 2 \cdot 10^5) — the length of the array aa, and the maximum number of times you can perform the operation.

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1091 \le a_i \le 10^9).

The sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5,1≤k≤2⋅1051 \le k \le 2 \cdot 10^5)——分别表示数组 aa 的长度以及你最多可执行操作的次数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤1091 \le a_i \le 10^9)。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output the maximum sum of aa achievable after playing the game.

对于每个测试用例,输出游戏结束后所能达到的 aa 的最大和。

输入输出样例

  • 输入#1

    7
    5 1
    1 1 5 5 5
    3 1
    10 1 2
    6 3
    1 1 2 3 1 2
    5 1
    1 2 2 3 5
    3 1
    332473521 409066963 155613323
    6 6
    81 71 90 15 87 36
    7 2
    4 13 11 19 15 16 10

    输出#1

    25
    13
    13
    14
    997420563
    522
    105

说明/提示

A way to achieve 2525 in the first test case is to select x=5x = 5 and then do:

  • [1,1,5,5,5]→[5,5,5,5,5][\color{red}1, \color{red}1, \color{red}5, \color{red}5, \color{red}5] \rightarrow [5, 5, 5, 5, 5]

A way to achieve 1313 in the third test case is to pick x=3x = 3 and then do:

  • [1,1,2,3,1,2]→[2,1,2,3,1,2]→[2,1,2,3,2,2]→[2,2,2,3,2,2][\color{red}1, 1, \color{red}2, 3, 1, \color{red}2] \rightarrow [\color{red}2, 1, \color{red}2, 3, \color{red}1, 2] \rightarrow [2, \color{red}1, \color{red}2, 3, \color{red}2, 2] \rightarrow [2, 2, 2, 3, 2, 2]

第一组测试数据中得到 2525 的一种方法是选择 x=5x = 5,然后执行以下操作:

  • [1,1,5,5,5]→[5,5,5,5,5][\color{red}1, \color{red}1, \color{red}5, \color{red}5, \color{red}5] \rightarrow [5, 5, 5, 5, 5]

第三组测试数据中得到 1313 的一种方法是选择 x=3x = 3,然后执行以下操作:

  • [1,1,2,3,1,2]→[2,1,2,3,1,2]→[2,1,2,3,2,2]→[2,2,2,3,2,2][\color{red}1, 1, \color{red}2, 3, 1, \color{red}2] \rightarrow [\color{red}2, 1, \color{red}2, 3, \color{red}1, 2] \rightarrow [2, \color{red}1, \color{red}2, 3, \color{red}2, 2] \rightarrow [2, 2, 2, 3, 2, 2]

输入解题思路,AI测评打分。不知道怎么写?

首页