-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
41 lines (29 loc) · 845 Bytes
/
solution.java
File metadata and controls
41 lines (29 loc) · 845 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
39
40
41
import java.util.*;
public class solution {
public static int count(int N, int[] A, int K, int budget) {
int count = 0;
for (int i = 0; i <= N - K; i++) {
int sum = 0;
for (int j = i; j < i + K; j++) {
sum += A[j];
}
if (sum <= budget) {
count++;
}
}
return count;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = scanner.nextInt();
}
int K = scanner.nextInt();
int budget = scanner.nextInt();
scanner.close();
int result = count(N, A, K, budget);
System.out.println(result);
}
}