Your solution will not work well with this: 250, 50, 50, 50, 50, 50, 1, 1, 1, 1
I would recommend something like this:
PHP Code:
new numbers[10] = { 1, 5, 3, 6, 7, 4, 9, 10, 2, 8 }
new group[2][5]
new group_cnt[2]
new group_sum[2]
for(new i=0; i<10; i++){
if(group_cnt[1] >= 5 || (group_cnt[0] < 5 && group_sum[0] <= group_sum[1])){
group[0][group_cnt[0]++] = numbers[i]
group_sum[0] += numbers[i]
}else{
group[1][group_cnt[1]++] = numbers[i]
group_sum[1] += numbers[i]
}
}
It will have better effect if you sort numbers in descending order.
__________________