Alien Threats U66360


Statement
 

pdf   zip

thehtml

Scientists have discovered spatial zones (represented by two-dimensional arrays) where aliens have been detected. The cells of each array contain an integer value indicating the density of aliens at that specific location. Scientists need to identify certain hotspots, or "critical zones" that might indicate an increased threat to humans.

Input

A sequence of spatial zones, terminated by a zero. Each zone is indicated by:

  • An integer n representing the number of rows in the matrix (1 ≤ n ≤ 100).
  • An integer m representing the number of columns in the matrix (1 ≤ m ≤ 100).
  • A matrix of size n × m containing non-negative integers representing the density of aliens in each cell of the matrix.
  • An integer k representing the size of the "analysis square" (1 ≤ kmin(n, m)). This square is a submatrix of size k × k that will be used to analyze hotspots.

Output

There are 3 pieces of information to be displayed:

  • For each spatial zone in the sequence, the position (row and column index) of the top left vertex of the k × k subsquare that contains the highest total alien density. If there is a tie between multiple subsquares, write the position of the subsquare with the lowest row position.
  • The total sum of alien densities within that subsquare.
  • The maximum density value within that subsquare.

Observation

It is mandatory to write at least one subroutine that reads an entire spatial zone. The subroutine receives a matrix by reference and fills it with values read from the input. However, it is probably convenient to create more subroutines for this problem.

Public test cases
  • Input

    2 2
    1 4
    3 9
    1
    
    3 5
    0 0 1 1 0
    0 0 2 3 0
    0 0 0 0 0
    2
    
    0
    

    Output

    (1,1)
    9
    9
    (0,2)
    7
    3
    
  • Input

    5 6
    4 2 1 6 3 5
    1 3 8 2 6 1
    7 2 9 5 4 2
    4 8 3 7 1 9
    2 6 4 8 3 2
    3
    0
    

    Output

    (2,1)
    52
    9
    
  • Information
    Author
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++