BOJ : https://www.acmicpc.net/problem/2003
github : https://github.com/junho0956/Algorithm/blob/master/2003/2003/2003.cpp
2개의 인덱스를 가지고 좌+1우+1로 왔다갔다 하면서 문제를 해결해주시면 됩니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <iostream>
using namespace std;
int arr[10001];
int N, M, ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> arr[i];
int left = 0, right = 0;
int sum = 0;
while (left <= right && left < N && right <= N) {
if (sum == M) ans++;
if (sum >= M) sum -= arr[left++];
else sum += arr[right++];
}
cout << ans;
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 1644번 소수의 연속합 (0) | 2020.01.31 |
---|---|
BOJ 1806번 부분합 (0) | 2020.01.31 |
BOJ 1987번 알파벳 (0) | 2020.01.31 |
BOJ 2580번 스도쿠 (0) | 2020.01.31 |
BOJ 2661번 좋은수열 (0) | 2020.01.31 |