PS/BOJ
[백준] 수들의 합2
RUBY_루비
2020. 9. 17. 23:59
출처:: www.acmicpc.net/problem/2003
분류:: 투포인터
1. 문제 이해 및 해결과정
2. 풀이방법
1. python
#수들의 합 2
#https://www.acmicpc.net/problem/2003
import sys
sys.stdin = open("input.txt","r")
n,m=map(int,input().split())
arr=list(map(int,input().split()))
s,e=0,0
cnt=0
sum=0
for s in range(n):
while sum<m and e<n:#합이 m보다 작고, 끝점이 n보다 작으면
sum+=arr[e]
e+=1
if sum==m: #부분합과 같으면
cnt+=1
#합이 m보다 크면
sum-=arr[s]
print(cnt)
3. 오답원인
4. 알게된 점