-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path2531.java
More file actions
35 lines (29 loc) · 1.1 KB
/
2531.java
File metadata and controls
35 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int[] sushiKinds = new int[d + 1];
int[] dishes = new int[N];
for (int i=0; i<N; i++) {
dishes[i] = Integer.parseInt(br.readLine());
}
int unique = 0;
for (int i=0; i<k-1; i++) {
if (sushiKinds[dishes[i]]++ == 0) unique++;
}
int result = 0;
for (int i=0; i<N; i++) {
if (sushiKinds[dishes[(i + k - 1) % N]]++ == 0) unique++;
result = Math.max(result, unique + (sushiKinds[c] == 0 ? 1 : 0));
sushiKinds[dishes[i]]--;
if (sushiKinds[dishes[i]] == 0) unique--;
}
System.out.print(result);
}
}