-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
28-SeongHoonC #205
28-SeongHoonC #205
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import sys
N, S = map(int,sys.stdin.readline().split())
numbers = list(map(int,sys.stdin.readline().split()))
start = 0
end = 0
accumulate = numbers[0]
answer = int(1e9)
while start <= end:
if accumulate >= S:
answer = min(answer, end-start+1)
accumulate -= numbers[start]
start+=1
elif accumulate < S:
if end == N-1: break
else:
end+=1
accumulate += numbers[end]
if answer == int(1e9): print(0)
else: print(answer)
μ΄ λ¬Έμ μ λ§ ν¬ ν¬μΈν° μ λ¬ΈνκΈ° μ’μ λ¬Έμ λΌκ³ μκ°λ©λλ€!
λ¬Έμ μΆμ² κ²μνμ κΈ νλ μ¬λ €μ£Όμ€ μ μλμ ?!
@tgyuuAn μ¬λ¦¬λ €κ³ νμΌλ ꡬκ΅μλμ΄ μ΄λ―Έ μ¬λ¦¬μ ¨κ΅°μ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ²μ μ΄ λ¬Έμ λ₯Ό λ³΄κ³ νΌμ μ΄ μλλ° μ΄λμ κ° νμ΄λ³Έ λλμΈλ°? νλλ
μ λ²μ μ¬λ¦¬μ
¨λ μμμ μ°μν© λ¬Έμ λ λΉμ·νλ€μ ~!
ν¬ ν¬μΈν° 볡μ΅νμ΅λλ€ :)
λ¬Έμ νΈλλΌ μκ³ νμ ¨μ΅λλ€ !!
import sys
def input() : return sys.stdin.readline().rstrip()
N, S = map(int, input().split())
arr = list(map(int, input().split()))
start = 0
end = 0
sum = arr[0]
total = int(1e9)
while start<=end:
if end >= len(arr) or start>= len(arr):
break
if sum >= S:
total = min(total, end-start+1)
sum -= arr[start]
start += 1
else:
end += 1
if end < N: sum += arr[end]
if total == int(1e9):
print(0)
else:
print(total)
π λ¬Έμ λ§ν¬
λΆλΆν©
βοΈ μμλ μκ°
30λΆ
β¨ μλ μ½λ
λ¬Έμ λ₯Ό 보μλ§μ μ΅μν¨μ΄ λκ»΄μ‘λ€.
head, tail μ head λΆν° tail μ΄μ κΉμ§μ ν©μ μ μ₯νλ sum μ λ§λ λ€.
2-1. κ°μκ° μ΅μμΈμ§ νμΈνκ³ μ΅μκ°μΌλ‘ λ΅μ μ λ°μ΄νΈνλ€.
2-2. head λ₯Ό μ¦κ°μν€κ³ sum μ arr[head] λ₯Ό λΊλ€.
μ κ³Όμ μ head < tail μ΄κ³ head, tail μ΄ λ°°μ΄μ μ¬μ΄μ¦λ₯Ό λκΈ°μ§ μμ λκΉμ§ λ°λ³΅νλ€.
π μλ‘κ² μκ²λ λ΄μ©