optimized best total cost algorithm