Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class MaxSumOf3x3 {
- public static void main(String[] args) throws Exception {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String[] tokens = in.readLine().split(" ");
- int a = Integer.parseInt(tokens[0]);
- int b = Integer.parseInt(tokens[1]);
- int[][] array=new int[a][b];
- for(int i=0;i<b;i++){
- String[] numbers = in.readLine().split(" ");
- for(int j=0;j<a;j++){
- array[i][j]=Integer.parseInt(numbers[j]);
- }
- }
- int maxSum=0;
- int currentSum=0;
- for(int i=0;i<a-2;i++){
- for(int j=0;j<b-2;j++){
- currentSum=sum(array,i,j);
- if(maxSum<=currentSum){
- maxSum=currentSum;
- }
- }
- }
- System.out.println(maxSum);
- }
- public static int sum(int[][] arraySum,int row,int col){
- int sum=0;
- for(int i=row;i<row+3;i++){
- for(int j=col;j<col+3;j++){
- sum+=arraySum[i][j];
- }
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement