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. dij+堆优化

    写这个dij+堆优化的原因是有些地方卡SPFA,只能搞这个: 香甜的奶油: #include<iostream> #include<cstdio> #include<cs ...

  2. input处理函数

    input处理函数是潜在的影响你app性能的问题,他们可以阻止帧的形成,并且可以造成多余的亦或不必要的layout的工作. 避免长时间运行input handler:它们会阻塞scroll 不要在in ...

  3. 【CQ18高一暑假前挑战赛1】标程

    [A] #include<bits/stdc++.h> using namespace std; #define ll long long ll qpow(ll a,ll x,ll Mod ...

  4. 「LuoguP1220」 关路灯(区间dp

    题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯. 为了给村 ...

  5. 如何理解Web应用程序的MVC模型?

    View,也就是视图/视野,是你真正看到的,而非想象中的 Model.Controller,也就是控制器,是你用来改变 Model 方式.简单的说 Controller 和 View 分别是 Mode ...

  6. android jni java类型与c语言类型互换

    1.java String转换 C str char* Jstring2CStr(JNIEnv* env, jstring jstr) { char* rtn = NULL; jclass clsst ...

  7. js的常用正则表达式

    1.在input框中只能输入金额,其实就是只能输入最多有两位小数的数字 //第一种在input输入框限制 <input type="text" maxlength=" ...

  8. ECMAScript 6 &ECMAScript 5(在线手册)

    https://www.w3.org/html/ig/zh/wiki/ES5#.E8.A1.A8.E8.BE.BE.E5.BC.8F      ECMAScript 5(在线手册) http://es ...

  9. Even Three is Odd

    题意: 问题是对于所有的长度为n,且$1<=ai<=n$的整数序列求 $\prod_{i=1}^{n-2}{max \{w_i,w_{i+1},w_{i+2}}\}$ 之和. 解法: 首先 ...

  10. 【Linux学习】Linux文件系统6—文件目录权限设置

    Linux文件系统6-文件目录权限设置 1.       chmod操作权限设置 chomd是用来改变文件或目录权限的命令,但只有文件的属主和超级权限用户root才有这种权限.通过chmod来改变文件 ...