Skip to content

Commit da21aaf

Browse files
authored
Merge pull request #941 from AlgorithmWithGod/lkhyun
[20250921] BOJ / G4 / 수들의 합 4 / 이강현
2 parents a5f6636 + 25e0350 commit da21aaf

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int N,K;
10+
static long[] A;
11+
12+
public static void main(String[] args) throws IOException {
13+
st = new StringTokenizer(br.readLine());
14+
N = Integer.parseInt(st.nextToken());
15+
K = Integer.parseInt(st.nextToken());
16+
17+
A = new long[N+1];
18+
st = new StringTokenizer(br.readLine());
19+
for (int i = 1; i <= N; i++) {
20+
A[i] = A[i-1] + Integer.parseInt(st.nextToken());
21+
}
22+
23+
Map<Long, Integer> SumCount = new HashMap<>();
24+
long count = 0;
25+
26+
SumCount.put(0L, 1);
27+
28+
for (int j = 1; j <= N; j++) {
29+
long target = A[j] - K;
30+
count += SumCount.getOrDefault(target, 0);
31+
32+
SumCount.put(A[j], SumCount.getOrDefault(A[j], 0) + 1);
33+
}
34+
bw.write(count + "\n");
35+
bw.close();
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)