bad solution, try Daynamic Programming