![]() |
2nd Central European Olympiad in InformaticsDay 1 - Problem C Fair Sharing |
Two brothers, Alan and Bob want to share a set of gifts. Each of the gifts should be given to either Alan or Bob, and none of the gifts can be split. Each gift has a positive integer value. Let A and B denote the total value of gifts received by Alan and Bob, respectively. The aim is to minimise the absolute value of the difference A-B. Write a program which computes the values A and B.
The first line of the text file INPUT.TXT contains N, the number of the gifts (1<=N<= 100). The rest of the input contains N positive integers, the values of the gifts. Each value is <=200.
Output Data
Write the two integers A and B.
Example input:7 28 7 11 8 9 7 27 | Example output:48 49 |
Let G be an array of the value of each gifts. i-th gift will be added to a subtotal of j to achieve a new subtotal of j+G[i] if S[j]<i (a gift cannot be added to a subtotal more than once) and S[j+G[i]]=None (we need some improvements here!)
![]() |
![]() |