#K95717. Grid Operations: Minimal and Maximal Sum
Grid Operations: Minimal and Maximal Sum
Grid Operations: Minimal and Maximal Sum
You are given a grid with n rows and m columns, where all cells are initially zero. You need to perform exactly r operations. In each operation, you have the freedom to choose one cell and increment its value by 1, or you can choose to increment every cell in the grid by 1. Your task is to determine the minimum and maximum possible sum of all cells in the grid after performing exactly r operations.
The key observations are:
- The minimum sum is achieved by applying all r operations to just one cell (i.e. the sum becomes
r
). - The maximum sum is obtained by incrementing every cell in the grid in each operation (thus, after each operation the grid sum increases by n \times m, and after r operations the total is r \times n \times m).
In mathematical terms, using \(r\) as the number of operations, \(n\) as the number of rows, and \(m\) as the number of columns:
[ \text{min_sum} = r ]
[ \text{max_sum} = r \times n \times m ]
inputFormat
The input consists of a single line containing three space-separated integers: n, m, and r, which represent the number of rows, the number of columns, and the number of operations, respectively.
outputFormat
Output a single line containing two integers separated by a space: the minimum and maximum possible sum of the grid after exactly r operations.
## sample2 2 1
1 4