There are x number of hotels, each with CAx number of rooms and a fixed room cost COx. There are y number of guests, each needs Dy days to stay in a hotel room. What algorithm shall I use to reduce the overall expenditure? Assume the total number of rooms in all hotels is greater than the number of guests. Will a greedy algorithm of filling up cheapest hotel rooms with guests who need long stays also globally optimal? Looking for code snippet with optimal solutions.