#K4141. Closed Polygon Formation
Closed Polygon Formation
Closed Polygon Formation
You are given a collection of line segment lengths. Determine whether it is possible to form a closed polygon using all these segments.
A closed polygon can be formed if and only if the sum of all the segment lengths is strictly greater than twice the length of the longest segment. In mathematical notation, if the segments have lengths \(a_1, a_2, \dots, a_n\), then a polygon is possible if and only if:
\(a_1 + a_2 + \cdots + a_n > 2 \times \max(a_1, a_2, \dots, a_n)\)
For example, given the segments [3, 5, 6, 7]
, we have \(3+5+6+7 > 2 \times 7\), so a polygon can be formed.
inputFormat
The input is provided via stdin with the following format:
- The first line contains an integer \(n\) which represents the number of segments.
- The second line contains \(n\) space-separated integers representing the lengths of the segments.
outputFormat
Output a single line to stdout containing yes
if it is possible to form a closed polygon, or no
otherwise.
4
3 5 6 7
yes