#K71552. Largest Triangle Perimeter
Largest Triangle Perimeter
Largest Triangle Perimeter
You are given an integer \(n\) and an array of \(n\) integers representing the heights of mountains. Your task is to determine the largest possible perimeter of a triangle that can be formed by choosing any three mountains as its vertices. A triangle is valid if it satisfies the triangle inequality, i.e., for sides \(a\), \(b\), and \(c\) (with \(a \ge b \ge c\)), the following condition holds:
\(a < b + c\)
If no valid triangle can be formed, output \(0\).
inputFormat
The input is given via standard input (stdin) and consists of two parts:
- The first line contains an integer \(n\) (\(3 \le n \le 10^5\)), the number of mountains.
- The second line contains \(n\) space-separated integers representing the heights of the mountains.
outputFormat
Output a single integer to standard output (stdout), which is the largest perimeter of a valid triangle that can be formed. If no valid triangle exists, output \(0\).
## sample5
2 1 2 4 5
11