Skip to content

Commit f3a0253

Browse files
authored
Merge pull request #1584 from AlgorithmWithGod/ksinji
[20251204] BOJ / G4 / 수들의 합 4 / 강신지
2 parents a660a36 + 5c9312e commit f3a0253

File tree

1 file changed

+36
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)