#P2088. Juice Machine Cleaning Minimization
Juice Machine Cleaning Minimization
Juice Machine Cleaning Minimization
During the hot summer, a glass of freshly squeezed and chilled juice is a delight. Xiao Wang saw a business opportunity and opened a juice shop near his school. He prepared \(K\) juicers and labeled different juices with numbers: \(1\) (orange juice), \(2\) (apple juice), \(3\) (grape juice), and so on. Each juicer can only be used to prepare one specific type of juice at a time.
When a customer orders a juice, if there is a juicer that has been used before to make that same juice, then it can be used again immediately. However, if the ordered juice is new (i.e. no juicer is currently assigned to that juice), then a clean juicer is required. If there is a clean juicer available, it is allocated to that juice without extra cost. Otherwise, Xiao Wang must clean one of the juicers currently in use, incurring a cleaning cost. Initially all juicers are clean.
Given the sequence of customer orders and knowing the number of juicers \(K\), determine the minimum number of times a juicer needs to be cleaned assuming an optimal cleaning strategy. This problem is analogous to the optimal page replacement (Belady's algorithm) where the goal is to minimize replacements.
inputFormat
The first line contains two integers \(N\) and \(K\) where \(N\) is the number of customer orders and \(K\) is the number of juicers available.
The second line contains \(N\) space-separated integers representing the juice types ordered by customers.
outputFormat
Output a single integer representing the minimum number of cleaning processes required.
sample
3 1
1 2 1
2