Advertisement
Guest User

Untitled

a guest
Feb 15th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class MaxSumOf3x3 {
  4. public static void main(String[] args) throws Exception {
  5. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  6. String[] tokens = in.readLine().split(" ");
  7. int a = Integer.parseInt(tokens[0]);
  8. int b = Integer.parseInt(tokens[1]);
  9. int[][] array=new int[a][b];
  10. for(int i=0;i<b;i++){
  11. String[] numbers = in.readLine().split(" ");
  12. for(int j=0;j<a;j++){
  13. array[i][j]=Integer.parseInt(numbers[j]);
  14. }
  15. }
  16. int maxSum=0;
  17. int currentSum=0;
  18. for(int i=0;i<a-2;i++){
  19. for(int j=0;j<b-2;j++){
  20. currentSum=sum(array,i,j);
  21. if(maxSum<=currentSum){
  22. maxSum=currentSum;
  23. }
  24. }
  25. }
  26. System.out.println(maxSum);
  27. }
  28. public static int sum(int[][] arraySum,int row,int col){
  29. int sum=0;
  30. for(int i=row;i<row+3;i++){
  31. for(int j=col;j<col+3;j++){
  32. sum+=arraySum[i][j];
  33. }
  34. }
  35. return sum;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement