-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon15961.cpp
More file actions
43 lines (37 loc) · 794 Bytes
/
baekjoon15961.cpp
File metadata and controls
43 lines (37 loc) · 794 Bytes
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
36
37
38
39
40
41
42
43
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;
int N, D, K, C, arr[3000001];
int start, cnt, answer;
unordered_map<int, int> m;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> D >> K >> C;
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
for (int i = 0; i < K - 1; i++) { // k 4면 0 1 2 3
m[arr[i]]++;
} // k개 넣어두고 시작
int fin = K - 1;
for(int i = 0 ; i < N ; i++){ // 회전초밥이므로 한 바퀴 돌자
int del = arr[start];
int cur = arr[fin%N];
m[cur]++;
int num = m.size();
if (m.find(C) == m.end()) { // 쿠폰용 초밥이 없다면 +1
answer = max(answer,num + 1);
}
else {
answer = max(answer, num);
}
m[del]--;
if (m[del] == 0)
m.erase(m.find(del));
start++;
fin++;
}
cout << answer;
}