问题 5306 --Mahmoud and a Triangle(小马和三角形)(triangle.cpp)

5306: Mahmoud and a Triangle(小马和三角形)(triangle.cpp)★★★

时间限制: 2 Sec  内存限制: 256 MB
提交: 1221  解决: 279
[提交][状态][命题人:]

题目描述

Mahmoud has n line segments, the i-th of them has length a[i]. Ehab challenged him to use exactly 3 line segments to form a triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a triangle.

Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. 

小马有 n 条线段,第 i 条线段的长度为 a[i]。小艾向他提出挑战,要求他用刚好 3 条线段组成一个三角形。小马不接受挑战除非他确定自己能赢,所以他让你告诉他是否应该接受挑战。给定线段的长度,检查他是否能从中选出恰好 3 个线段组成三角形。
小马应该正好使用 3 个线段,他不能连接两个线段或改变任何长度。

输入

The first line contains single integer n (3 ≤ n ≤ 1e5) — the number of line segments Mahmoud has.

The second line contains n integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 1e9) — the lengths of line segments Mahmoud has.

第一行包含单个整数 n (3≤n≤1e5)—小马拥有的线段的数量。
第二行包含n个整数 a[1], a[2],…, a[n](1≤a[i]≤1e9)——小马拥有的线段的长度。

输出

In the only line print "YES" if he can choose exactly three line segments and form a triangle with them, and "NO" otherwise.

如果小马能够组成一个三角形,输出“YES”(不带引号),否则输出“NO”(不带引号)。

样例输入
Copy
样例输入1
5
1 5 3 2 4
样例输入2
3
4 1 2
样例输出
Copy
样例输入1
YES
样例输入2
NO

提示

For the first example, he can use line segments with lengths 24 and 5 to form a triangle.

对于第一个例子,他可以使用长度为2、4和5的线段来组成一个三角形。

来源

 

[提交][状态]