Optimization (finding the minimum cost)