562-dividing Coins
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=503
It ' s commonly known that Dutch have invented Copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and fighting is so fierce, They stretched the coin to great length and thus created Copper-wire. Not commonly known was that the fighting started, after the two Dutch-tried to divide a bag with coins between the two of T Hem. The contents of the bag appeared is equally divisible. The Dutch of the past couldn ' t stand the fact that a division should favour one of them and they always a wanted fair E to the very last cent. Nowadays fighting over a single cent won't be seen anymore, but being capable of making a equal division as fair as PO Ssible is something that would remain important forever ...
That ' s what this whole problem is about. Not everyone is capable of seeing instantly what ' s most fair division of a bag of coins between-two. Your help are asked to solve this problem.
Given a bag with a maximum of coins, determine the most fair, division and between two persons. This means difference between the amount of each person obtains should to be minimised. The value of a coin varies from 1 cent to cents. It ' s not allowed to split a single coin.
Input
Line A and the number of problems N, followed by N times:
A line with a non negative an integer m() indicating the number of coins in the bag
Line A and M numbers separated by one spaces, each number indicates the value of a coin.
Output
The output consists of n lines. Each line contains the minimal positive difference between the amount the two persons-obtain when they divide the coins fr Om the corresponding bag.
Sample Input
2
3
2 3 5
4
1 2 4 6
Sample Output
0
1
Thinking: Equivalence transformation. Equal amount (capacity) for sum the package is equivalent to using those coins to install a SUM/2 bag (the remaining coin is another package), this is not 0-1 backpack it ~