欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1440B.Sum of Medians
Sum of Medians
A median of an array of integers of length is the number standing on the (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with . For example, a median of the array is equal to . There exist some other definitions of the median, but in this problem, we will use the described one.
Given two integers and and non-decreasing array of integers. Divide all numbers into arrays of size , such that each number belongs to exactly one array.
You want the sum of medians of all arrays to be the maximum possible. Find this maximum possible sum.
Input
The first line contains a single integer () — the number of test cases. The next lines contain descriptions of test cases.
The first line of the description of each test case contains two integers , ().
The second line of the description of each test case contains integers () — given array. It is guaranteed that the array is non-decreasing: .
It is guaranteed that the sum of for all test cases does not exceed .
Output
For each test case print a single integer — the maximum possible sum of medians of all arrays.
Note
The examples of possible divisions into arrays for all test cases of the first test:
Test case : . The medians are . Their sum is .
Test case : . The medians are . Their sum is .
Test case : . The medians are . Their sum is .
Test case : $[3, 33, 35], [11, 94, 99], [12, 38, 67], [22, 69, 71]$. The medians are . Their sum is .
Test case : . The median is . The sum of the only median is .
Test case : . The medians are . Their sum is .
Samples
6
2 4
0 24 34 58 62 64 69 78
2 2
27 61 81 91
4 3
2 4 16 18 21 27 36 53 82 91 92 95
3 4
3 11 12 22 33 35 38 67 69 71 94 99
2 1
11 41
3 3
1 1 1 1 1 1 1 1 1
165
108
145
234
11
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |