Constructing a Cyclic Quadrilateral
Time limit1sMemory limit512 MB
Given three decreasing segment lengths where the longest is a diameter of the circumscribed circle, find the fourth side of the cyclic quadrilateral or print -1.
- Level
Easy3 of 10
- Topics
- Geometry, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
A quadrilateral is cyclic if its four vertices lie on a circle. You are given the lengths of three line segments, and the longest of them equals the diameter of the circle on which the quadrilateral is inscribed. Find the length of the remaining segment.
Input
The first line contains three integers representing the lengths of the three segments. () The three segments are given in decreasing order.
Output
Print the length of the remaining side on the first line. If no cyclic quadrilateral can be formed, print -1. The answer is guaranteed to be an integer in every test case.
Hint
By Ptolemy's theorem, for a cyclic quadrilateral the sum of the products of the two pairs of opposite sides equals the product of the two diagonals.

