Problem 2994 --K Subsequence

2994: K Subsequence

"
Time Limit $2$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Master QWsin is dating with Sindar. And now they are in a restaurant, the restaurant has nn dishes in order. For each dish, it has a delicious value aiai. However, they can only order kk times. QWsin and Sindar have a special ordering method, because they believe that by this way they can get maximum happiness value. 

Specifically, for each order, they will choose a subsequencesubsequence of dishes and in this subsequencesubsequence, when i<ji<j, the subsequence must satisfies ai≤ajai≤aj. After a round, they will get the sum of the subsequencesubsequence and they can't choose these dishes again. 

Now, master QWsin wants to know the maximum happiness value they can get but he thinks it's too easy, so he gives the problem to you. Can you answer his question? 
There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case: 

First line contains two positive integers nn and kk which are separated by spaces. 

Second line contains nn positive integer a1a1,a2a2,a3a3...anan represent the delicious value of each dish. 


1≤T≤51≤T≤5 

1≤n≤20001≤n≤2000 

1≤k≤101≤k≤10 

1≤ai≤1e51≤ai≤1e5 
Only an integer represent the maximum happiness value they can get.
1

9 2
5 3 2 1 4 2 1 4 6
22

推荐代码 查看2994 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$798 $ms] intLSY 474436 2019-09-26 20:23:25
内存最少[$26108 $KB] intLSY 474436 2019-09-26 20:23:25
第一AC intLSY 474436 2019-09-26 20:23:25
第一挑战 intLSY 474436 2019-09-26 20:23:25

赛题来源/所属竞赛 2019 Multi-University Training Contest 3 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛