N,S = map(int,input().split()) arr = list(map(int,input().split())) start,end = 0,0 temp = 0 result = float('inf') while start <= end: if temp >= S: temp = temp - arr[start] result = min(result,end - start) start += 1 elif end == N: start += 1 else: temp = temp + arr[end] end += 1 if result == float('inf'): print(0) else: print(result)
투 포인터를 활용한 문제이고, 투포인터를 이용해서, 주어진 S 값이 넘어갔을때 최소 길이를 비교해주는 방식으로 했다.
'알고리즘 > 백준' 카테고리의 다른 글
[BOJ/백준] 1300 K번째 수 (0) | 2021.04.08 |
---|---|
[BOJ/백준] 1967 트리의 지름 (0) | 2021.04.08 |
[BOJ/백준] 10868 최소 값 찾기 (0) | 2021.03.20 |
[BOJ/백준] 2042 구간 합 구하기 (0) | 2021.03.12 |
[BOJ/백준] 2075 N번째 큰 수 (0) | 2021.03.12 |