-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
54 lines (48 loc) · 1.44 KB
/
Main.java
File metadata and controls
54 lines (48 loc) · 1.44 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
44
45
46
47
48
49
50
51
52
53
54
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
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());
StringTokenizer st2 = new StringTokenizer(br.readLine());
List<Integer> numbers = new ArrayList<>();
while (st2.hasMoreTokens()) {
numbers.add(Integer.valueOf(st2.nextToken()));
}
int Lp = 0;
int Rp = 0;
int minv = (int) 1e9;
int total = numbers.get(0);
while (true) {
if (Lp > Rp) {
break;
}
if (total < S) {
Rp += 1;
if (Rp >= N) {
break;
}
total += numbers.get(Rp);
} else {
minv=Integer.min(minv,Rp-Lp+1);
total-=numbers.get(Lp);
Lp += 1;
if (Lp>=N){
break;
}
}
}
if(minv==(int) 1e9){
System.out.println(0);
}
else {
System.out.println(minv);
}
}
}