-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_1806.java
More file actions
39 lines (32 loc) · 1.06 KB
/
baekjoon_1806.java
File metadata and controls
39 lines (32 loc) · 1.06 KB
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
import java.io.*;
import java.util.*;
public class baekjoon_1806 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int S = Integer.parseInt(st.nextToken());
int[] arr = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int start = 0;
int end = 0;
int min = Integer.MAX_VALUE;
int sum = arr[start];
while (start <= end) {
if (sum >= S) {
min = Math.min(min, end - start + 1);
sum -= arr[start];
start++;
} else {
end++;
if (end == N) break;
sum += arr[end];
}
}
int res = min == Integer.MAX_VALUE ? 0 : min;
System.out.println(res);
}
}