#P10620. [ICPC 2013 WF] Low Power
[ICPC 2013 WF] Low Power
题目描述
You are building advanced chips for machines. Making the chips is easy, but the power supply turns out to be an issue since the available batteries have varied power outputs.
Consider the problem of machines, each with two chips, where each chip is powered by batteries. Surprisingly, it does not matter how much power each chip gets, but a machine works best when its two chips have power outputs as close as possible. The power output of a chip is simply the smallest power output of its batteries.
You have a stockpile of 2nk batteries that you want to assign to the chips. It might not be possible to allocate the batteries so that in every machine both chips have equal power outputs, but you want to allocate them so that the differences are as small as possible. To be precise, you want to tell your customers that in all machines the difference of power outputs of the two chips is at most , and you want to make as small as possible. To do this you must determine an optimal allocation of the batteries to the machines.
Consider Sample Input . There are machines, each requiring batteries per chip, and a supply of batteries with power outputs . You can, for instance, assign the batteries with power outputs to one chip, those with power to the other chip of the same machine, those with power to the third chip, and those with power to the fourth. The power outputs of the chips are and , respectively, and the difference between power outputs is in both machines. Note that there are many other ways to achieve this result.
输入格式
The input consists of a single test case. A test case consists of two lines. The first line contains two positive integers: the number of machines and the number of batteries per chip . The second line contains integers specifying the power outputs of the batteries .
输出格式
Display the smallest number such that you can allocate the batteries so that the difference of power outputs of the two chips in each machine is at most .
2 3
1 2 3 4 5 6 7 8 9 10 11 12
1
2 2
3 1 3 3 3 3 3 3
2
