Maximize The Beautiful Value++
题号:NC13888
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 128 M,其他语言256 M
64bit IO Format: %lld

题目描述

The term of this problem is the same as the problem "Maximize The Beautiful Value", the only exception — The sequence may not necessary to to non-decreasing.
"Maximize The Beautiful Value": https://ac.nowcoder.com/acm/problem/13887

输入描述:

 The first line contains an positive integer T(1≤T≤10), represents there are T test cases. 
 For each test case: 
 The first line contains two positive integers n,k(1≤n≤105,1≤k<n),the length of the sequence ,the least steps you need to move. 
 The second line contains n integers a1,a2…an(1≤ai≤108) - the sequence.

输出描述:

For each test case, you should output the max F(n).
示例1

输入

复制
4
5 3
1 1 3 4 5
5 2
1 1 3 4 5
5 1
1 1 3 4 5
5 3
3 5 4 1 1

输出

复制
46
50
53
43

说明

In the forth example, you can move the fifth number 1 for 4 steps and then the sequence becomes [1,3,5,4,1]