Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate 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 non-degenerate triangle.

Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.

Input

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

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the lengths of line segments Mahmoud has.

Output

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

Examples
input
5
1 5 3 2 4
output
YES
input
3
4 1 2
output
NO
Note

For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.

题意:选出三个数字看能不能构成三角形

解法:

1 根据三角形的特点,排序求出两小点的和以及两大点的差,符合条件就输出

2 好吧,貌似只要找出两小点的和大于第三点就行

 #include<bits/stdc++.h>
using namespace std;
int a[];
int frsum[];
int afsum[];
int main(){
int n;
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
}
sort(a+,a++n);
for(int i=;i<=n-;i++){
frsum[i]=a[i-]+a[i];
afsum[i]=a[i+]-a[i];
}
for(int i=;i<=n-;i++){
if(frsum[i]>a[i]&&afsum[i]<a[i-]){
cout<<"YES"<<endl;
return ;
}
}
cout<<"NO"<<endl;
return ;
}

Codeforces Round #396 (Div. 2) B的更多相关文章

  1. Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集

    D. Mahmoud and a Dictionary 题目连接: http://codeforces.com/contest/766/problem/D Description Mahmoud wa ...

  2. Codeforces Round #396 (Div. 2) A,B,C,D,E

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  4. Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary

    地址:http://codeforces.com/contest/766/problem/D 题目: D. Mahmoud and a Dictionary time limit per test 4 ...

  5. Codeforces Round #396 (Div. 2) D

    Mahmoud wants to write a new dictionary that contains n words and relations between them. There are ...

  6. Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑

    E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and ...

  7. Codeforces Round #396 (Div. 2) C. Mahmoud and a Message dp

    C. Mahmoud and a Message 题目连接: http://codeforces.com/contest/766/problem/C Description Mahmoud wrote ...

  8. Codeforces Round #396 (Div. 2) B. Mahmoud and a Triangle 贪心

    B. Mahmoud and a Triangle 题目连接: http://codeforces.com/contest/766/problem/B Description Mahmoud has ...

  9. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  10. Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip

    地址:http://codeforces.com/contest/766/problem/E 题目: E. Mahmoud and a xor trip time limit per test 2 s ...

随机推荐

  1. Codeforces Round #295 (Div. 2)---B. Two Buttons( bfs步数搜索记忆 )

    B. Two Buttons time limit per test : 2 seconds memory limit per test :256 megabytes input :standard ...

  2. HDU1133 Buy the Ticket —— 卡特兰数

    题目链接:https://vjudge.net/problem/HDU-1133 Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Me ...

  3. Telnet连接远程服务器

    使用Telnet远程连接服务器端 现在大多数人使用win7系统.在win7系统中默认已经安装好了telnet服务,我们只需要从服务中将其打开即可, 步骤在首先打开控制面板-->卸载程序--> ...

  4. SSL peer shut down incorrectly

    这个问题通常出现在Android Studio更新失败的时候, 原因是download http://services.gradle.org/distributions/gradle-2.2-all. ...

  5. HDFS副本设置——默认3

    首先 dfs.replication这个参数是个client参数,即node level参数.需要在每台datanode上设置. 其实默认为3个副本已经够用了,设置太多也没什么用. 一个文件,上传到h ...

  6. OpenCV——Perlin Noise

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  7. CF 809D Hitchhiking in the Baltic States——splay+dp

    题目:http://codeforces.com/contest/809/problem/D 如果值是固定的,新加入一个值,可以让第一个值大于它的那个长度的值等于它. 如今值是一段区间,就对区间内的d ...

  8. alsa音频驱动框架

    sound/core/sound.c 实现了最顶层的file_operations,它起中转作用 sound/core/control.c 实现了控制接口的file_operations sound/ ...

  9. vue全局配置

    Vue.config 是一个对象,包含Vue的全局配置.可以在启动应用之前修改下列的属性: Vue.config.slient=true;      取消Vue所有的日志与警告   默认值false ...

  10. <正则吃饺子> :关于前端往后端传递布尔值参数的问题

    问题是在一个群里看到的,通过自己查找和实验,参考网上的博文,将问题列出来.以帮助后来者和共同交流学习.   博文地址:http://blog.sina.com.cn/s/blog_13c30757a0 ...