B. Mahmoud and a Triangle
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

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.

——————————————————————————————————

题目是在n个线段中曲靖个问能不能构成三角形

从小到大排序,然后判连续的3个能不能构成三角形即可

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=1000005; int a[MAXN];
int n;
int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int flag=0;
for(int i=0;i<n-2;i++)
{
if(a[i]+a[i+1]>a[i+2]) {
flag=1;
break;
}
}
if(flag==1)
printf("YES\n");
else
printf("NO\n");
} return 0;
}

Codeforces766B Mahmoud and a Triangle 2017-02-21 13:47 113人阅读 评论(0) 收藏的更多相关文章

  1. Codeforces 766C Mahmoud and a Message 2017-02-21 13:57 62人阅读 评论(0) 收藏

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. Codeforces766A Mahmoud and Longest Uncommon Subsequence 2017-02-21 13:42 46人阅读 评论(0) 收藏

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  3. hdu 1033 (bit masking, utilization of switch, '\0' as end of c string) 分类: hdoj 2015-06-15 21:47 37人阅读 评论(0) 收藏

    bit masking is very common on the lower level code. #include <cstdio> #include <algorithm&g ...

  4. C语言基础:结构体 分类: iOS学习 c语言基础 2015-06-10 21:47 28人阅读 评论(0) 收藏

    结构体:是一种用户自定义的数据类型 结构体定义 struct 结构体名 {     成员类型1  成员变量名1;     成员类型2  成员变量名2;      -. }; typedef   原类型 ...

  5. 哈夫曼树-Fence Repair 分类: 树 POJ 2015-08-05 21:25 2人阅读 评论(0) 收藏

    Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417 Descri ...

  6. Safecracker 分类: HDU 搜索 2015-06-25 21:12 12人阅读 评论(0) 收藏

    Safecracker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...

  7. 排序练习——找出前m大的数字 分类: 排序 2015-06-08 09:33 21人阅读 评论(0) 收藏

    排序练习--找出前m大的数字 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给定n个数字,找出前m大的数字.   输入  多组输 ...

  8. hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏

    problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...

  9. shell入门之函数应用 分类: 学习笔记 linux ubuntu 2015-07-10 21:48 77人阅读 评论(0) 收藏

    最近在学习shell编程,文中若有错误的地方还望各位批评指正. 先来看一个简单的求和函数 #!/bin/bash #a test about function f_sum 7 8 function f ...

随机推荐

  1. 冒泡排序算法-Python实现

    #-*- coding: UTF-8 -*- import numpy as np def BubbleSort(a): for i in xrange(0, a.size): for j in xr ...

  2. 【转】open-falcon监控windows机器

    open-falcon监控windows机器 时间:2016-05-22 15:34:04   来源:眷恋江南   编辑:涛涛   点击:791   A-A+     最近公司上线了一款新的游戏,用的 ...

  3. C BIN加密

    #include <stdio.h> #include <string.h> #include <stdlib.h> #ifndef DWORD #define D ...

  4. <只看这个就够了。。。>Android自动化测试及性能优化

    Android自动化测试及性能优化 分类: Android Java Tools2012-12-09 23:31 4300人阅读 评论(0) 收藏 举报 软件自动化测试对于程序员来说能够确保软件开发的 ...

  5. KMP算法解释

    给定两个字符串A,B,判断T是否为S的子串(变式:寻找子串B在串A中的位置). 要求一个O(|A|+|B|)的做法. 通常称A为目标串(或主串),B为模式串. 算法过程: 我们假设串A的长度为n,串B ...

  6. PHP扩展类ZipArchive实现压缩解压Zip文件和文件打包下载 && Linux下的ZipArchive配置开启压缩 &&搞个鸡巴毛,写少了个‘/’号,浪费了一天

    PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PHP ZIP 扩展已经开启,具体开启方法就不说了,不同的平台开启PHP扩增的方法网上都有,如有 ...

  7. JavaScript(二)-精简

    十三 DOM(文档对象模型) 1 作用 : 可访问javascript HTML文档的所有元素. 2 功能: (1) 改变html输出流 eg: <script>              ...

  8. Windows 上用IntelliJ Idea调试百度大数据分析框架Apache Doris FE

    A. 环境准备 1. 安装jdk1.8+, Intelij IDEA 2. linux上编译好fe前端代码,主要目的是获取自动生成的代码,加入到前段工程里面去用于在idea中编译fe工程.具体编译请参 ...

  9. Oracle11g 搭建单实例DataGuard (转载)

    原文:http://blog.itpub.net/29324876/viewspace-1246133/ 环境:主备库都为单实例并且数据库SID相同 OS:red hat 6.5 Oracle:11. ...

  10. todolist_高级写法

    <!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" conten ...