Name: Anonymouse 2010-02-28 14:52
You are given an array of integers. You have to find the shortest substring that contains only the elements from the interval [ A, B ]. Also, every integer from the interval [ A, B ] has to appear at least once in the substring. If there is no such substring output -1.
INPUT:
The first line contains three integers n, A and B (1 <= n <= 1.000.000, 1 <= A <= B <= 1.000.000.000). The following line contains n integers from the interval [1, 1.000.000.000] representing the array.
OUTPUT:
Output the length of such shortest substring, or -1 if there is none.
Input:
22 5 7
5 7 8 6 1 1000 6 7 7 7 5 5 5 5 7 7 7 7 7 6 6 6
Output:
5
Explanation:
The shortest substring exists, its length is 5. It starts from the 7th element of the array.
INPUT:
The first line contains three integers n, A and B (1 <= n <= 1.000.000, 1 <= A <= B <= 1.000.000.000). The following line contains n integers from the interval [1, 1.000.000.000] representing the array.
OUTPUT:
Output the length of such shortest substring, or -1 if there is none.
Input:
22 5 7
5 7 8 6 1 1000 6 7 7 7 5 5 5 5 7 7 7 7 7 6 6 6
Output:
5
Explanation:
The shortest substring exists, its length is 5. It starts from the 7th element of the array.