File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.BufferedReader ;
3+ import java.io.IOException ;
4+ import java.io.InputStreamReader ;
5+
6+ // TIP 코드를 <b>실행</b>하려면 <shortcut actionId="Run"/>을(를) 누르거나
7+ // 에디터 여백에 있는 <icon src="AllIcons.Actions.Execute"/> 아이콘을 클릭하세요.
8+ public class Main {
9+ private static BufferedReader br;
10+ private static int [] arr;
11+ private static int s;
12+ private static int n;
13+
14+ public static void main (String [] args ) throws IOException {
15+ br = new BufferedReader (new InputStreamReader (System . in));
16+ String [] temp = br. readLine(). split(" " );
17+ n = Integer . parseInt(temp[0 ]);
18+ s = Integer . parseInt(temp[1 ]);
19+ arr = new int [n];
20+ int i = 0 ;
21+ for (String token: br. readLine(). split(" " )){
22+ arr[i++ ] = Integer . parseInt(token);
23+ }
24+
25+ int r = 0 ;
26+ int l = 0 ;
27+ int sum = 0 ;
28+ int answer = Integer . MAX_VALUE ;
29+ while (l < arr. length){
30+ if (r == arr. length){
31+ sum -= arr[l++ ];
32+ }else
33+ if (sum < s){
34+ // 오른쪽에서 하나 추가해서 더해줘야함
35+ sum += arr[r++ ];
36+ }else {
37+ // 왼쪽에서 하나 제거해서 빼줘야함
38+ sum -= arr[l++ ];
39+ }
40+ if (sum >= s) answer = Math . min(answer, r - l);
41+ }
42+ if (answer == Integer . MAX_VALUE ){
43+ System . out. println(0 );
44+ }else
45+ System . out. println(answer);
46+ br. close();
47+ }
48+ }
49+ ```
You can’t perform that action at this time.
0 commit comments