import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int s = kb.nextInt();
int[] nums = new int[n+1];
for (int i = 0; i < n; i++) {
nums[i] = kb.nextInt();
}
int minLength = Integer.MAX_VALUE;
int sum = 0;
int lt = 0, rt = 0;
while(rt<= n) {
if(sum>=s) {
minLength = Math.min(rt-lt, minLength);
sum -= nums[lt++];
}else {
sum += nums[rt++];
}
}
if (minLength == Integer.MAX_VALUE) {
System.out.println(0);
} else {
System.out.println(minLength);
}
}
}
'공부기록 > 백준' 카테고리의 다른 글
[백준] 2908번 상수 (0) | 2023.12.20 |
---|---|
[백준] 2675번 문자열 반복 (0) | 2023.12.20 |
[백준] 1759번 암호 만들기 (0) | 2023.12.19 |
[백준] 1182번 부분수열의 합 (0) | 2023.12.19 |
[백준] 2161번 카드1 (0) | 2023.12.19 |