-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20922.py
More file actions
31 lines (28 loc) · 820 Bytes
/
20922.py
File metadata and controls
31 lines (28 loc) · 820 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
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
nums = list(map(int, input().split()))
left = 0
right = 0
answer = 1
cur_nums = dict()
while right < n:
# 이미 해당 번호가 존재하는 경우
if cur_nums.get(nums[right], 0):
# 넣었을 때 k개 이하라면
if cur_nums.get(nums[right]) + 1 <= k:
cur_nums[nums[right]] += 1
right += 1
answer = max(answer, right - left)
else:
while nums[left] != nums[right]:
cur_nums[nums[left]] -= 1
left += 1
cur_nums[nums[left]] -= 1
left += 1
# 해당 번호가 처음 등장하는 경우
else:
cur_nums[nums[right]] = 1
right += 1
answer = max(answer, right - left)
print(answer)