๋ฌธ์
https://www.acmicpc.net/problem/1806
ํ์ด
# ๋ฐฑ์ค 1806๋ฒ ๋ฌธ์ - ๋ถ๋ถํฉ
import sys
input = sys.stdin.readline
n, s = map(int, input().split())
num = list(map(int, input().split()))
target, left, right = 0, 0, 0
min_length = 1e9
while True:
# print("left: ", left, " right: ", right)
if target >= s:
min_length = min(min_length, right - left)
target -= num[left]
left += 1
else:
if right == n:
break
target += num[right]
right += 1
if min_length == 1e9:
print(0)
else:
print(min_length)
ํฌํฌ์ธํฐ ๋ฌธ์ ๋ ์ฒ์ ํ์ด๋ด์ ๋ฌธ์ ๋ฅผ ์ ๊ทผํ๋๋ฐ ์ด๋ ค์์ด ์์๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 1976๋ฒ_์ฌํ ๊ฐ์ (1) | 2023.04.03 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 9935๋ฒ_๋ฌธ์์ด ํญ๋ฐ (0) | 2023.04.03 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 11722๋ฒ_๊ฐ์ฅ ๊ธด ๊ฐ์ํ๋ ๋ถ๋ถ ์์ด (0) | 2023.03.31 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 2636๋ฒ_์น์ฆ (0) | 2023.03.31 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 1744๋ฒ_์ ๋ฌถ๊ธฐ (0) | 2023.03.31 |