#K83372. Largest Triangular Number
Largest Triangular Number
Largest Triangular Number
You are given a list of positive integers representing side lengths. Your task is to determine the largest perimeter of any triangle that can be formed using three of these integers.
A triangle is valid if it satisfies the triangle inequality: \(a+b>c\), \(a+c>b\), and \(b+c>a\), where \(a\), \(b\), and \(c\) are the side lengths.
If no valid triangle can be formed, output -1
.
inputFormat
The first line contains an integer n
, the number of side lengths. The second line contains n
space-separated positive integers representing the side lengths.
outputFormat
Output a single integer representing the largest triangle perimeter possible, or -1
if no valid triangle can be formed.
5
2 1 2 1 2
6
</p>