Control C401B P42596


Statement
 

pdf   zip

html

Your task is to write a program that reads a sequence of matrices of integers, and prints which of them has the maximum difference between its greatest element and the smallest element. In case of a tie, you must choose the matrix that appeared before in the sequence.

Using the definition

typedef vector<vector<int> > Matrix;

your program must implement and use the procedure

void min_max(const Matrix& mat, int& minimum, int& maximum);

that, given the non empty matrix mat, leaves at minimum and at maximum the elements minimum and maximum of mat, respectively.

Input

The input is a non empty sequence of non empty matrices of integers. Each matrix is described with its size n > 0 and m > 0, followed by its n × m elements.

Output

The output is two lines indicating which is the maximum difference between the maximum element and minimum element of each matrix, and which is the first matrix with this difference.

Public test cases
  • Input

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

    Output

    la diferencia maxima es 7
    la primera matriu amb aquesta diferencia es la 2
    
  • Input

    1 1
    4
    

    Output

    la diferencia maxima es 0
    la primera matriu amb aquesta diferencia es la 1
    
  • Information
    Author
    Professorat de P1
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++