- 포인터를 이용하는 문제
- 부분집합의 합이 M이 되는 경우의 수 구하는 문제
- 원소 1개 = M일 때도 인정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
n, m=map(int, input().split())
a=list(map(int, input().split()))
lt, rt = 0, 1
tot=a[0]
cnt=0
while True:
if tot < m:
if rt < n:
tot+=a[rt]
rt+=1
else: #rt가 n에 도달하면 while문 탈출
break
elif tot == m:
cnt+=1
tot-=a[lt]
lt+=1
else:
tot-=a[lt]
lt+=1
print(cnt)
|
cs |
728x90
'Data Structures & Algorithms' 카테고리의 다른 글
[Algorithms] Basic-곶감(모래시계) (0) | 2022.05.14 |
---|---|
[Algorithms] Basic-사과나무(다이아몬드) (0) | 2022.05.14 |
[Algorithms] Basic-두 리스트 합치기 (0) | 2022.05.13 |
[Algorithms] Basic-뒤집은 소수 (0) | 2022.05.12 |
[Algorithms] Basic-소수(에라토스테네스 체) (0) | 2022.05.12 |