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

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

Codeforces Mahmoud and a Triangle (水

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

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南召县| 茌平县| 喀什市| 福泉市| 铜梁县| 襄汾县| 法库县| 淮滨县| 沙雅县| 满洲里市| 泰宁县| 溆浦县| 颍上县| 东平县| 惠安县| 渭南市| 昭平县| 抚顺市| 定西市| 淅川县| 绥中县| 绍兴市| 色达县| 冀州市| 靖远县| 华亭县| 达日县| 灵丘县| 新余市| 兴和县| 岢岚县| 无极县| 中阳县| 会理县| 吉林省| 赣榆县| 泊头市| 稻城县| 呼伦贝尔市| 抚远县| 阳东县|