#C11177. Triangle Formation Challenge
Triangle Formation Challenge
Triangle Formation Challenge
Given a collection of wood pieces, determine whether any three pieces can form a non‐degenerate triangle. According to the triangle inequality theorem: for any three sides a, b, c, they can form a triangle if and only if:
\(a + b > c\), \(a + c > b\), and \(b + c > a\).
After sorting the pieces, it is sufficient to check consecutive triples. Your task is to read the list of pieces, and output True
if there exists a valid triplet that can form a triangle or False
otherwise.
inputFormat
The input is given via standard input. The first line contains an integer n representing the number of wood pieces. The second line contains n space-separated integers, each representing the length of a wood piece.
outputFormat
Output a single line to standard output with True
if any three pieces can form a triangle, and False
otherwise.
3
2 3 4
True