Shouldn't set the subsets be {1 3 9} and {8 5} to give each subset a total of 13? Also your program gives a difference of 1 not 2 for {9 51 308 107 27 91 62 176 28 6}. To understand how it produces...