-
Notifications
You must be signed in to change notification settings - Fork 138
/
Solution.java
37 lines (32 loc) · 906 Bytes
/
Solution.java
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int solve(int n, int[] s, int d, int m){
if (m > n) { return 0; }
int counter = 0;
int acc = 0;
for (int i = 0; i < m; i++) { acc += s[i]; }
for (int i = m; i < n; i++) {
if (acc == d) { counter++; }
acc += s[i];
acc -= s[i - m];
}
if (acc == d) { counter++; }
return counter;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] s = new int[n];
for(int s_i=0; s_i < n; s_i++){
s[s_i] = in.nextInt();
}
int d = in.nextInt();
int m = in.nextInt();
int result = solve(n, s, d, m);
System.out.println(result);
}
}