SHARE
TWEET

Untitled

a guest May 25th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $inputSize = array_map('intval',explode(', ', readline()));
  3. $rows = $inputSize[0];
  4. $cols = $inputSize[1];
  5. $matrix = [];
  6. for ($row = 0; $row < $rows; $row++){
  7.     $matrix[$row] = array_map('intval', explode(', ', readline()));
  8. }
  9. $max = 0;
  10. $startRow = 0;
  11. $startCol = 0;
  12. for ($row = 0; $row < count($matrix) - 1; $row++){
  13.     for ($col = 0; $col < count($matrix[$row]) - 1; $col++){
  14.         $currentSum = $matrix[$row][$col]
  15.                     + $matrix[$row][$col + 1]
  16.                     + $matrix[$row + 1][$col]
  17.                     + $matrix[$row + 1][$col + 1];
  18.         if ($currentSum > $max){
  19.             $max = $currentSum;
  20.             $startRow = $row;
  21.             $startCol = $col;
  22.         }
  23.     }
  24. }
  25. for ($row = $startRow; $row < $startRow + 2; $row++){
  26.     for ($col = $startCol; $col < $startCol + 2; $col++){
  27.         echo $matrix[$row][$col] . " ";
  28.     }
  29.     echo PHP_EOL;
  30. }
  31. echo $max;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top