国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Codeforces Mahmoud and a Triangle (水

2019-11-09 21:02:25
字體:
來源:轉載
供稿:網友

B. Mahmoud and a Triangle

time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

ExamplesInput
51 5 3 2 4Output
YESInput
34 1 2Output
NONote

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

題意: 給一組數,從中挑選三個數字是否為三角形(只要有一組符合就可以 解析: 利用兩邊之和第三邊就可以

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 100005int arr[N]; bool cmp(int x,int y){ return x > y;} int main(){ int n; while(~scanf("%d",&n)) { bool flag = false; for(int i = 0;i < n; i++) { scanf("%d",&arr[i]); } sort(arr,arr+n,cmp); for(int i = 0;i < n-2; i++) { if(arr[i] < arr[i+1]+arr[i+2]) { printf("YES/n"); flag = true; break; } } if(!flag) { printf("NO/n"); } }return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 密云县| 永济市| 康马县| 诸城市| 衡阳县| 扶风县| 姚安县| 濮阳县| 穆棱市| 育儿| 尼木县| 葫芦岛市| 昭平县| 新宁县| 福安市| 义乌市| 定南县| 乌兰浩特市| 霍山县| 翼城县| 容城县| 金沙县| 平定县| 长阳| 龙川县| 亚东县| 满城县| 泰州市| 梧州市| 长白| 准格尔旗| 革吉县| 仁怀市| 龙州县| 涪陵区| 卫辉市| 昔阳县| 全椒县| 大英县| 金塔县| 大名县|