I need an algorith to solve this problem

Printable View