A community orchard is arranged as a rectangular grid of R rows and C columns of plots, and every plot has a recorded yield (in kilograms) for the current growing season. A plot's yield is called a balance point if it is the smallest yield anywhere in its own row and, at the same time, the largest yield anywhere in its own column. Given the yield of every plot, report the yield of every balance point.
Print one line containing the yield of every balance point, one number per qualifying plot, in non-decreasing order, separated by single spaces. If a value ties as the minimum of its row (or the maximum of its column) at more than one position, each qualifying plot still contributes its own entry to the output, so the same value can legitimately appear more than once. If no plot is a balance point, print an empty line.
Example 1
Input
3 3 30 10 40 90 50 95 25 20 60
Expected
50
Explanation
Row minimums are 10 (row 0), 50 (row 1), 20 (row 2). Column maximums are 90 (col 0), 50 (col 1), 95 (col 2). Only the plot with yield 50 at row 1, column 1 is both its row's minimum and its column's maximum, so it is the only balance point.
Example 2
Input
2 2 1 2 2 1
Expected
(empty)Explanation
Row minimums are 1 (row 0, at column 0) and 1 (row 1, at column 1). Column maximums are 2 (col 0) and 2 (col 1). Neither row-minimum plot (value 1) equals its column's maximum (value 2), so there are no balance points and the output is an empty line.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →