You and a greedy classmate win a large sack of gems. You take the gems to a reputable gem appraiser who determines the value of each gem. One of you wants to sell the gems and split the profit down the middle, but the other wants to hold onto the gems. You ask your data structures teacher for advice, and she suggests that the two of you divide up the rocks (no gem can be split in two, tho) in the following manner: it is your job to divide the gems into two piles; your classmate gets to choose which pile he/she wants.
Write a Java program that takes as input a list of gem values and divides the gems into two piles such that the sum of the values of the rocks in the two piles is close to equal. The values can be any positive integer that does not exceed 50,000. You may assume that the sum of the values does not exceed the maximum integer value for 32 bit integers.
Gem Values: 26004 39663 29502 40739 14724 15188 48659 47360 3106 777 6038 5010 33108 213 26954 43668 Pile #1. 48659 40739 39663 29502 26004 5010 777 Sum: 190354 Pile #2. 47360 43668 33108 26954 15188 14724 6038 3106 213 Sum: 190359
Gem Values: 25342 12858 14827 15960 35321 18784 24278 23101 9727 44395 25120 41247 9868 27622 1796 16221 29060 11148 39333 45273 10494 3486 44636 19997 15941 5572 41958 22909 20382 45803 37723 12075 25012 18901 28034 26685 37684 18664 49785 47410 13058 24905 38657 39278 2526 6804 5498 47937 34304 11183 Pile #1. 49785 47937 47410 45803 45273 44636 44395 41958 41247 39333 39278 38657 37723 27622 11148 6804 3486 1796 Sum: 614291 Pile #2. 37684 35321 34304 29060 28034 26685 25342 25120 25012 24905 24278 23101 22909 20382 19997 18901 18784 18664 16221 15960 15941 14827 13058 12858 12075 11183 10494 9868 9727 5572 5498 2526 Sum: 614291