-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path수들의 합 2.java
More file actions
42 lines (33 loc) · 1.04 KB
/
수들의 합 2.java
File metadata and controls
42 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 수들의 합 2
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[] arr = new int[n];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int left = 0, right = 0, cnt = 0;
int sum = 0;
while (right < n) {
sum += arr[right];
right++;
if (sum == m) {
cnt++;
}
while (sum >= m && left < right) {
sum -= arr[left];
left++;
if (sum == m)
cnt++;
}
}
System.out.println(cnt);
}
}