forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa00108_MaximumSum.java
39 lines (34 loc) · 1.24 KB
/
UVa00108_MaximumSum.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 44 (108 - Maximum Sum) */
/* SUBMISSION: 08752965 */
/* SUBMISSION TIME: 2011-04-17 01:38:10 */
/* LANGUAGE: 2 */
import java.util.*;
public class UVa00108_MaximumSum {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int N = in.nextInt();
int[][] mat = new int[N][N];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
mat[i][j] = in.nextInt();
int max = Integer.MIN_VALUE;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int[] sumc = new int[N - j];
int[] sumr = new int[N - j];
for (int m = i; m < N; ++m) {
for (int n = j; n < N; ++n) {
sumc[n - j] = (n - j - 1 >= 0 ? sumc[n - j - 1] : 0) + mat[m][n];
sumr[n - j] += sumc[n - j];
max = Math.max(max, sumr[n - j]);
}
}
}
}
System.out.println(max);
}
}
}