File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed
Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 20144 KB, 시간: 1236 ms
7+ 메모리: 19568 KB, 시간: 180 ms
88
99### 분류
1010
1111누적 합, 두 포인터
1212
1313### 제출 일자
1414
15- 2025년 6월 5일 18:52:23
15+ 2025년 6월 5일 19:22:25
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 11import java .io .*;
2- import java .util .*;
32
43public class Main {
54
6- static int n ;
7- static int [] arr , cw , ccw ;
5+ static int n , sum ;
6+ static int [] arr ;
87 static BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
98 public static void main (String [] args ) throws Exception {
109 inputSetting ();
1110 System .out .println (findMaxLen ());
1211 }
1312
1413 static int findMaxLen (){
15- int answer = 0 ;
14+ int answer = -1 ;
15+ int r , l , min , now ;
16+ r = 0 ;
17+ l = 0 ;
18+ now = arr [0 ];
1619
17- for (int i = 0 ; i < n ; i ++){
18- for (int j = i + 1 ; j < n ; j ++){
19- answer = Math .max (answer , Math .min (cw [j ] - cw [i ], cw [n ] - (cw [j ] - cw [i ])));
20- }
20+ while (l <= r && r < n ){
21+ min = Math .min (now , sum - now );
22+ answer = Math .max (min , answer );
23+
24+ if (min == now ) now += arr [++r ];
25+ else now -= arr [l ++];
2126 }
2227 return answer ;
2328 }
2429
2530 static void inputSetting () throws Exception {
2631 n = Integer .parseInt (br .readLine ());
27- arr = new int [n ];
28- cw = new int [n + 1 ];
32+ arr = new int [n + 1 ];
2933
3034 for (int i = 0 ; i < n ; i ++){
3135 arr [i ] = Integer .parseInt (br .readLine ());
32- cw [ i + 1 ] += cw [ i ] + arr [i ];
36+ sum += arr [i ];
3337 }
3438 }
3539}
You can’t perform that action at this time.
0 commit comments