3. [re] 부분합

아현·2021년 9월 15일
0

Algorithm

목록 보기
320/400

백준


1. 투포인터



import sys
input = sys.stdin.readline
n, s = map(int, input().split())
array = list(map(int, input().split()))
lst = [0] * (n + 1)

for i in range(1, n + 1):
    lst[i] = lst[i - 1] + array[i - 1]

result = sys.maxsize
left = 0
right = 1

while left < n:
    if lst[right] - lst[left] >= s:
        if right - left < result:
            result = right - left
        left += 1

    else:
        if right < n:
            right += 1
        else:
            left += 1

if result >= sys.maxsize:
    print(0)
else:
    print(result)

profile
Studying Computer Science

0개의 댓글