#B4098. Minimum Ticket Cost to See All Animals
Minimum Ticket Cost to See All Animals
Minimum Ticket Cost to See All Animals
A zoo has venues numbered and animal types numbered (with ). Each venue houses exactly one animal, although different venues may house the same species.\n\nThe ticketing system is special: when buying a ticket, a visitor must specify a starting venue and an ending venue . The printed ticket shows these two numbers, and the visitor is only allowed to visit venues through (inclusive). The cost is calculated as $$10 \times (b - a + 1).$$\n\nLittle Ming wants to see all animal types while spending as little as possible. However, he can only purchase one ticket. Determine the minimum amount of money he must spend to see all animal types (it is acceptable to see the same type more than once).
inputFormat
The input consists of two lines:\ The first line contains two integers and ().\ The second line contains integers, where the -th integer represents the animal type at venue (an integer between and ).
outputFormat
Output a single integer representing the minimum ticket cost required to visit a contiguous block of venues that includes all animal types.
sample
8 3
1 2 3 1 2 3 2 1
30