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

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

Codeforces Mahmoud and a Triangle (水

2019-11-10 18:35:13
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 独山县| 增城市| 潢川县| 凤山县| 舒城县| 锡林郭勒盟| 平山县| 贡觉县| 麻栗坡县| 乡城县| 岑巩县| 辽宁省| 卓尼县| 泗洪县| 秭归县| 永年县| 富川| 麻江县| 怀集县| 祁阳县| 神农架林区| 连山| 湘潭县| 和林格尔县| 东阿县| 清水河县| 辽阳市| 连山| 上虞市| 海丰县| 阿拉尔市| 建宁县| 江陵县| 伊川县| 京山县| 南京市| 峨边| 镇巴县| 安庆市| 墨脱县| 谷城县|