Title Description
AsiaWorld-Expo is being exhibited by the best in the world M painters painted pictures.
wangjy think Expo to see that several masters.
However, where the Expo have a very strange rule is that two figures must be stated in the purchase of tickets,
a and b, between the representatives of all the pictures he wanted to see the exhibition of a web through b picture (and contains a b), while tickets
The price is a picture of one yuan.
To see more teacher's paintings, wangjy would like to see a picture after the admission of all teachers (at least each one).
But he wanted to save money. . .
As wangjy friend, he asks you to write a program that he decided a and b values when buying tickets.
Input Format
The first row is N and M, representing the total number of pictures and Expo hall The pictures are drawn by how many bits the teacher
The painting.
Subsequent row comprising N digital, they are between 1 and M, representing the number of bits teacher.
Output Format
a and b (a <= b) is separated by a space character.
To ensure a solution, if multiple solutions, minimum output a.
Sample input and output
12 5
2 5 3 1 3 2 4 1 1 5 4 3
2 7
Description / Tips
30% of the agreed data N <= 200, M <= 20
60% of the data N <= 10000, M <= 1000
100% data N <= 1000000, M <= 2000
[Problem-solving ideas]
Similarly greedy sliding window.
Consider violence. Enumeration right point, greedy find a best left point, to determine whether the interval length better, update the answer.
【code】
1 #include<stdio.h>
2 int m[2001],num;
3 int n[1000000];
4 int main()
5 {
6 int R=-1,L=0,N,M,t,i=0,ansL,ansR;
7 scanf("%d%d",&N,&M);
8 for(i=0;i<N;i++)
9 scanf("%d",n+i);
10 i=0;
11 while(num!=M)
12 {
13 if(m[n[i]]==0)num++;
14 m[n[i]]++;
15 R++;
16 i++;
17 }
18 while(m[n[L]]>1)
19 m[n[L++]]--;
20 ansL=L;ansR=R;
21 while(i<N)
22 {
23 m[n[i]]++;
24 R++;
25 i++;
26 while(m[n[L]]>1)
27 m[n[L++]]--;
28 if(ansR-ansL>R-L)
29 {
30 ansR=R;
31 ansL=L;
32 }
33 }
34 printf("%d %d",ansL+1,ansR