-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp2003.java
More file actions
32 lines (28 loc) · 983 Bytes
/
p2003.java
File metadata and controls
32 lines (28 loc) · 983 Bytes
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
// Arrays.sort(arr)을 하면 오답처리가 된다. 왜그런지 생각해보자
import java.io.*;
import java.util.*;
public class p2003 {
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 lo = 0, hi = 0, sum = 0, cnt = 0;
while (true) {
if (sum >= m) {
sum -= arr[lo++];
} else if (hi >= n) {
break;
} else {
sum += arr[hi++];
}
if (sum == m) cnt++;
}
System.out.println(cnt);
}
}