E.g.

A | B | C | weight |
---|---|---|---|

5 | 6 | 1 4 9 3 1 2 | 20 |

5 | 6 1 | 4 9 3 1 2 | 19 |

5 | 6 1 4 | 9 3 1 2 | 15 |

5 | 6 1 4 9 | 3 1 2 | 20 |

5 | 6 1 4 9 3 | 1 2 | 23 |

5 | 6 1 4 9 3 1 | 2 | 24 |

5 6 | 1 | 4 9 3 1 2 | 19 |

5 6 | 1 4 | 9 3 1 2 | 15 |

5 6 | 1 4 9 | 3 1 2 | 14 |

5 6 | 1 4 9 3 | 1 2 | 17 |

5 6 | 1 4 9 3 1 | 2 | 18 |

5 6 1 | 4 | 9 3 1 2 | 15 |

5 6 1 | 4 9 | 3 1 2 | 13 |

5 6 1 | 4 9 3 | 1 2 | 16 |

5 6 1 | 4 9 3 1 | 2 | 17 |

5 6 1 4 | 9 | 3 1 2 | 16 |

5 6 1 4 | 9 3 | 1 2 | 16 |

5 6 1 4 | 9 3 1 | 2 | 16 |

5 6 1 4 9 | 3 | 1 2 | 25 |

5 6 1 4 9 | 3 1 | 2 | 25 |

5 6 1 4 9 3 | 1 | 2 | 28 |

This is far from optimal, but it will result in all possible solutions and you can chose the (one) minimal one.

The number of permutations is:

- given: 3 brothers, N numbers

- permutations: 1+0.5*N*(N-3)

- E.g. N=8 --> permutations = 1+0.5*8*5 = 21

- E.g. N=20 --> permutations = 1+0.5*20*17=171

Now you need to define an algorithm that creates the permutations.

A possible algorithm gives to each permutation a unique id, e.g. 1,1,6 is A=1, B=1, C=6 numbers, i.e. the first permutation of the table above. In the given case, 3,2,3 is the optimum.

E.g. a crude algorithm that keeps the last minimal solution could be implemented as follows

N = ... Salary[0...N-1] = ... Min = Sum(Salary[0...N-1]) Permutation = [0,0,0] for A=1 to N-2 do loop for B=1 to N-1-A do loop ProfitA = Sum(Salary[0...A-1]) ProfitB = Sum(Salary[A...A+B-1]) ProfitC = Sum(Salary[A+B...N-1]) ProfitMax = Max(ProfitA, ProfitB, ProfitC) if Min is greater than ProfitMax then Min = ProfitMax Permutation = [A,B,C] end if end loop end loop Print Min : PermutationOnly then you should start writing C code.

I leave this as exercise to implement in C.

Cheers

Andi