CF1690E.Price Maximization
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A batch of n goods ( n — an even number) is brought to the store, i -th of which has weight ai . Before selling the goods, they must be packed into packages. After packing, the following will be done:
- There will be 2n packages, each package contains exactly two goods;
- The weight of the package that contains goods with indices i and j ( 1≤i,j≤n ) is ai+aj .
With this, the cost of a package of weight x is always ⌊kx⌋ burles (rounded down), where k — a fixed and given value.
Pack the goods to the packages so that the revenue from their sale is maximized. In other words, make such 2n pairs of given goods that the sum of the values ⌊kxi⌋ , where xi is the weight of the package number i ( 1≤i≤2n ), is maximal.
For example, let n=6,k=3 , weights of goods a=[3,2,7,1,4,8] . Let's pack them into the following packages.
- In the first package we will put the third and sixth goods. Its weight will be a3+a6=7+8=15 . The cost of the package will be ⌊315⌋=5 burles.
- In the second package put the first and fifth goods, the weight is a1+a5=3+4=7 . The cost of the package is ⌊37⌋=2 burles.
- In the third package put the second and fourth goods, the weight is a2+a4=2+1=3 . The cost of the package is ⌊33⌋=1 burle.
With this packing, the total cost of all packs would be 5+2+1=8 burles.
输入格式
The first line of the input contains an integer t ( 1≤t≤104 ) —the number of test cases in the test.
The descriptions of the test cases follow.
The first line of each test case contains two integers n ( 2≤n≤2⋅105 ) and k ( 1≤k≤1000 ). The number n — is even.
The second line of each test case contains exactly n integers a1,a2,…,an ( 0≤ai≤109 ).
It is guaranteed that the sum of n over all the test cases does not exceed 2⋅105 .
输出格式
For each test case, print on a separate line a single number — the maximum possible total cost of all the packages.
输入输出样例
输入#1
6 6 3 3 2 7 1 4 8 4 3 2 1 5 6 4 12 0 0 0 0 2 1 1 1 6 10 2 0 0 5 9 4 6 5 5 3 8 6 3 2
输出#1
8 4 0 2 1 5
说明/提示
The first test case is analyzed in the statement.
In the second test case, you can get a total value equal to 4 if you put the first and second goods in the first package and the third and fourth goods in the second package.
In the third test case, the cost of each item is 0 , so the total cost will also be 0 .