A cook needs 12 pounds of flour. He wants to spend the least amount of money. If a 2-pound bag costs $1.59 and a 5-pound bag costs $2.89, how many bags of each type of flour should he buy? What will be the total cost?