CF2154E.No Mind To Think
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of positive integers a of length n and a positive integer k, and you will play the following game with them:
- At the start of the game, you will choose an odd integer x (1≤x≤n).
- Then do the following at most k times (possibly none):
- Select a subsequence of a of length x, then replace every value in the subsequence with the median∗ of that subsequence. More formally, pick x integers i1,…,ix (1≤i1<i2<…<ix≤n). Then simultaneously do aid:= median([ai1,ai2,…,aix]) for all d (1≤d≤x).
Note that the integer x you choose cannot change between operations.
Determine the maximum value for the sum of a obtainable after playing the game.
∗The median of an array a of length n (written median(a)) is the ⌊2n+1⌋-th smallest element in a, where ⌊x⌋ denotes the largest integer which is smaller than or equal to x. For example, median([4,3,1,2,5])=3 and median([4,3,5,3])=3.
给你一个长度为 n 的正整数数组 a 和一个正整数 k,你将与它们进行如下游戏:
- 游戏开始时,你需要选择一个奇数 x(满足 1≤x≤n)。
- 然后最多执行 k 次(也可不执行)以下操作:
- 从 a 中选出一个长度为 x 的子序列,并将该子序列中每个值都替换为该子序列的中位数∗。更准确地说,选取 x 个下标 i1,…,ix(满足 1≤i1<i2<…<ix≤n),然后对所有 d(1≤d≤x)同时令 aid:=median([ai1,ai2,…,aix])。
注意:你在整个过程中选定的 x 值不能更改。
求游戏结束后数组 a 元素之和所能达到的最大值。
∗ 长度为 n 的数组 a 的中位数(记作 median(a))定义为 a 中第 ⌊2n+1⌋ 小的元素,其中 ⌊x⌋ 表示不超过 x 的最大整数。例如,median([4,3,1,2,5])=3,而 median([4,3,5,3])=3。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains integers n and k (3≤n≤2⋅105, 1≤k≤2⋅105) — the length of the array a, and the maximum number of times you can perform the operation.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109).
The sum of n across all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(3≤n≤2⋅105,1≤k≤2⋅105)——分别表示数组 a 的长度以及你最多可执行操作的次数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output the maximum sum of a achievable after playing the game.
对于每个测试用例,输出游戏结束后所能达到的 a 的最大和。
输入输出样例
输入#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 25 in the first test case is to select x=5 and then do:
- [1,1,5,5,5]→[5,5,5,5,5]
A way to achieve 13 in the third test case is to pick x=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]
第一组测试数据中得到 25 的一种方法是选择 x=5,然后执行以下操作:
- [1,1,5,5,5]→[5,5,5,5,5]
第三组测试数据中得到 13 的一种方法是选择 x=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]
输入解题思路,AI测评打分。不知道怎么写?