https://www.acmicpc.net/problem/15565
코드
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
dolls = list(map(int, input().split()))
l = 0
answer = n+1
lion = 0
for r in range(n):
if dolls[r] == 1:
lion += 1
while lion >= k:
if lion == k and dolls[l] == 1:
break
if dolls[l] == 1:
lion -= 1
l += 1
if lion == k:
answer = min(answer, r-l+1)
print(answer if answer != n+1 else -1)
'문제풀이 > 투포인터' 카테고리의 다른 글
[Python/파이썬] 백준 15831번 준표의 조약돌 (1) | 2025.01.03 |
---|---|
[Python/파이썬] 백준 1253번 좋다 (0) | 2024.06.28 |
[Python/파이썬] SW Expert Academy 20728번 공평한 분배 2 (0) | 2024.06.13 |
[Python/파이썬] 백준 11687번 팩토리얼 0의 개수 (0) | 2024.02.25 |
[Python/파이썬] 백준 2559번 수열 (0) | 2024.01.31 |