-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_1806.java
More file actions
33 lines (26 loc) · 1 KB
/
baekjoon_1806.java
File metadata and controls
33 lines (26 loc) · 1 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
import java.util.*;
import java.io.*;
public class baekjoon_1806 {
public static void main(String[] args) throws Exception{
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[] nums = new int[n + 1];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++) {
nums[i] = Integer.parseInt(st.nextToken());
}
int min = Integer.MAX_VALUE;
int start = 0;
int end = 0;
int total = 0;
while(start <= n && end <= n) {
if(total >= s && min > end - start) min = end - start;
if(total < s) total += nums[end++];
else total -= nums[start++];
}
if(min == Integer.MAX_VALUE) System.out.println("0");
else System.out.println(min);
}
}