File tree Expand file tree Collapse file tree 4 files changed +45
-6
lines changed
Expand file tree Collapse file tree 4 files changed +45
-6
lines changed Original file line number Diff line number Diff line change 1+ # 2017-10-12 풀이 목록
2+ * Two Pointer[ 코드 보기] ( twopointer/Main.java )
13# 2017-10-05 풀이 목록
24* Sliding Window[ 코드 보기] ( slidingwindow/Main.java )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+ import java .io .*;
3+ /**
4+ * Main
5+ */
6+ public class Main {
7+ static BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
9+ public static void main (String [] args ) throws IOException {
10+
11+ String str1 [] = br .readLine ().split (" " );
12+
13+ int min = Integer .MAX_VALUE ;
14+ int sum = 0 ;
15+ int N = Integer .parseInt (str1 [0 ]), M = Integer .parseInt (str1 [1 ]);
16+
17+ String str2 [] = br .readLine ().split (" " );
18+ int arr [] = new int [N ];
19+ int l =0 ,r =0 ;
20+ for (int i = 0 ; i <N ; i ++){
21+ arr [i ] = Integer .parseInt (str2 [i ]);
22+ }
23+ sum =arr [0 ];
24+ while (true ){
25+ if (sum <M ){
26+ r ++;
27+ if (r <N )
28+ sum +=arr [r ];
29+ else
30+ break ;
31+ }else {
32+ sum -= arr [l ];
33+ min = Math .min (min , r -l +1 );
34+ l ++;
35+ }
36+ }
37+ if (min == Integer .MAX_VALUE )
38+ bw .write ("0" );
39+ else
40+ bw .write (String .valueOf (min ));
41+ bw .flush ();
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments