A framing workshop is choosing which rectangular canvas to mount on a display easel. Each candidate canvas is described by its length and width in centimeters. The workshop always mounts the canvas whose corner-to-corner diagonal brace is the longest, since that canvas needs the sturdiest support. If two or more candidate canvases tie for the longest diagonal, the workshop picks the one among the tied candidates that has the largest surface area. Given the list of candidate canvases, report the surface area of the canvas that gets mounted.
Line 1: one integer n — the number of candidate canvases. The next n lines (or, equivalently, the next 2n integers) each contain two integers, length and width, describing one candidate canvas.
Print a single integer: the area of the chosen canvas (the one with the longest diagonal, breaking ties by the largest area).
Example 1
Input
2 9 3 8 6
Expected
48
Explanation
The first canvas (9 by 3) has diagonal^2 = 9^2 + 3^2 = 90; the second (8 by 6) has diagonal^2 = 8^2 + 6^2 = 100. Since 100 > 90, the second canvas has the strictly longer diagonal and is chosen; its area is 8 * 6 = 48.
Example 2
Input
2 3 4 4 3
Expected
12
Explanation
Both canvases (3 by 4 and 4 by 3) have diagonal^2 = 3^2 + 4^2 = 4^2 + 3^2 = 25, a tie. Both also have the same area, 3*4 = 4*3 = 12, so the chosen canvas's area is 12.
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 →