Write a program that takes an integer N and an array of N integers as input. Your program should output the maximum perimeter of a triangle that can be made if we take exactly 3 integers from the inputted array and form a triangle. Your program should output -1 if it's not possible to create a triangle with the inputted values.
Note: The integer N will be given in the first line and the array of N integers will be given in the second line (each integer separated by a single space).
Example:
Case 1:
For the input provided as follows:
3
1 2 3
Output of the program will be:
-1
Description of the output:
It's not possible to create a triangle with values 1, 2 and 3.
Case 2:
For the input provided as follows:
4
1 1 1 1
Output of the program will be:
3
Description of the output:
The maximum perimeter we can get is by taking 1, 1 and 1 and create a triangle that gives 3 as perimeter.
6/02/2019
Đăng ký:
Đăng Nhận xét (Atom)






0 comments:
Đăng nhận xét