Ice Cream Machines
InterviewTime limit2sMemory limit1024 MB
Given a queue of flavour requests and k machines, find the fewest machine cleanings needed to serve every customer in order.
- Level
Medium5 of 10
- Topics
- Greedy, Simulation, Array
- Solved
- No attempts yet
Problem
Arnar is a true Icelander and loves ice cream. Today a blizzard is blowing, but he heads to his favourite ice cream store anyway. When he arrives, the queue is unusually short. He is the th person waiting to order. The store offers flavours and has ice cream machines. Each machine can serve only one flavour at a time, and a machine must be cleaned before it is loaded with a different flavour. Cleaning takes time, and Arnar is in a hurry. Each time a new flavour is needed for a customer, the store operator picks which machine to clean. Arnar wants to minimize the total number of cleanings. Arnar knows everyone in the queue and the flavour each person wants. The store has a strict no-cutting policy, so customers are served in arrival order. Find the minimum number of cleanings needed to serve all customers, including Arnar. Initially every machine is empty and must be cleaned before its first flavour. Once a machine is loaded with a flavour, it can serve any number of customers who want that flavour until it is cleaned and loaded with another flavour. A machine that is never used does not need cleaning.
Input
The first line has three integers , , and : the number of customers in the queue, the number of flavours, and the number of ice cream machines. Each of the next lines contains an integer (), the flavour wanted by the -th customer in the queue.
Output
Output the minimum total number of cleanings needed to serve all customers.