34void distribute(
int number,
unsigned groups,
const unsigned *ratios,
37 int i, sum = 0, rest[groups], max_groups[groups], max_count, max;
39 const int original_number = number;
56 for (i = 0; i < groups; i++) {
61 for (i = 0; i < groups; i++) {
62 result[i] = number * ratios[i] / sum;
66 for (i = 0; i < groups; i++) {
67 rest[i] = number * ratios[i] - result[i] * sum;
71 for (i = 0; i < groups; i++) {
79 for (i = 0; i < groups; i++) {
84 }
else if (rest[i] == max) {
85 max_groups[max_count] = i;
92 result[max_groups[0]]++;
93 rest[max_groups[0]] = 0;
96 int min = result[max_groups[0]], which_min = max_groups[0];
101 for (i = 1; i < max_count; i++) {
102 if (result[max_groups[i]] < min) {
103 min = result[max_groups[i]];
104 which_min = max_groups[i];
114 number = original_number;
115 for (i = 0; i < groups; i++) {