-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
38 lines (32 loc) · 981 Bytes
/
Solution.java
File metadata and controls
38 lines (32 loc) · 981 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
33
34
35
36
37
38
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class Solution {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int n = scan.nextInt();
scan.nextLine();
List<Integer> s = Arrays.stream(scan.nextLine().split(" "))
.map(Integer::parseInt)
.collect(Collectors.toList());
int d = scan.nextInt();
int m = scan.nextInt();
scan.close();
System.out.println(birthday(s, d, m));
}
static int birthday(List<Integer> s, int d, int m) {
if (s.size() < m) return 0;
int count = 0;
int i = 0;
while (i + m <= s.size()) {
int sum = 0;
for (int j = i; j < i + m; j++) {
sum += s.get(j);
}
if (sum == d) count++;
i++;
}
return count;
}
}