File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class JW_1749 {
2
+
3
+ public static void main (String [] args ) throws Exception {
4
+ int n = read (), m = read (), max = Integer .MIN_VALUE ;
5
+ int [][] dp = new int [n + 1 ][m + 1 ];
6
+ for (int i = 1 ; i < n + 1 ; i ++)
7
+ for (int j = 1 ; j < m + 1 ; j ++)
8
+ // (i, j)까지의 누적합
9
+ dp [i ][j ] = read () + dp [i - 1 ][j ] + dp [i ][j - 1 ] - dp [i - 1 ][j - 1 ];
10
+ for (int i = 1 ; i < n + 1 ; i ++)
11
+ for (int j = 1 ; j < m + 1 ; j ++)
12
+ for (int k = 1 ; k < i + 1 ; k ++)
13
+ for (int l = 1 ; l < j + 1 ; l ++) {
14
+ // 부분 배열의 누적합 구하기
15
+ max = Math .max (max , dp [i ][j ] - dp [k - 1 ][j ] - dp [i ][l - 1 ] + dp [k - 1 ][l - 1 ]);
16
+ }
17
+ System .out .println (max );
18
+ }
19
+
20
+ private static int read () throws Exception {
21
+ int c , n = System .in .read () & 15 ;
22
+ boolean m = n == 13 ;
23
+ if (m )
24
+ n = System .in .read () & 15 ;
25
+ while ((c = System .in .read ()) >= 48 )
26
+ n = (n << 3 ) + (n << 1 ) + (c & 15 );
27
+ if (c == 13 )
28
+ System .in .read ();
29
+ return m ? ~n + 1 : n ;
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments