-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1806.java
More file actions
43 lines (36 loc) · 1.16 KB
/
boj1806.java
File metadata and controls
43 lines (36 loc) · 1.16 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
40
41
42
43
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class boj1806 {
static int N, S;
static int[] nums;
static int left = 0;
static int right = 0;
static StringTokenizer st;
static int sum = 0;
static int answer = 100001;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
S = Integer.parseInt(st.nextToken());
nums = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
nums[i] = Integer.parseInt(st.nextToken());
}
while (true) {
if (sum >= S) {
sum -= nums[left];
answer = Math.min(answer, (right - left));
left++;
} else if (right == N) {
break;
} else {
sum += nums[right++];
}
}
System.out.println((answer == 100001 ? 0 : answer));
}
}