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

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

Codeforces Mahmoud and a Triangle (水

2019-11-09 20:49:51
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 正镶白旗| 临颍县| 神农架林区| 南投县| 邢台市| 陇川县| 商河县| 麻江县| 保山市| 东丰县| 隆回县| 疏附县| 永和县| 漳平市| 洪江市| 大石桥市| 鲁山县| 宾川县| 深州市| 大英县| 临颍县| 凤台县| 高陵县| 苍南县| 临泉县| 辽阳县| 阳江市| 三河市| 克东县| 田东县| 湘阴县| 清原| 延吉市| 剑川县| 邯郸市| 鸡泽县| 徐闻县| 乾安县| 会同县| 垫江县| 漳州市|