Description

standard input/output
Announcement

 
  • Statements

    There is a set of n segments with the lengths li. Find a segment with an integer length so that it could form a non-degenerate triangle with any two segments from the set, or tell that such segment doesn't exist.

Input

The first line contains a single integer n(2 ≤ n ≤ 200000) — the number of segments in the set.

The second line contains n integers li separated by spaces (1 ≤ li ≤ 109) — the lengths of the segments in the set.

Output

If the required segment exists, in the first line output «YES» (without quotes). In this case in the second line output a single integer x — the length of the needed segment. If there are many such segments, output any of them.

If the required segment doesn't exist, output «NO» (without quotes).

Sample Input

 

Input
2
3 4
Output
YES
2
Input
3
3 4 8
Output
YES
6
Input
3
3 4 9
Output
NO
题意:给你一些边 判断是否存在一条边 使得和其中的任意两条边组合都能形成三角形 

题解:将边排序之后 所要添加的边存在上下界
ans1=a[n-1]-a[0];     
ans2=a[0]+a[1];
范围内 任意输出 1 #include<bits/stdc++.h>
using namespace std;
int n;
int a[];
int ans1,ans2;
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
ans1=a[n-]-a[];
ans2=a[]+a[];
if(ans1+<ans2)
{
cout<<"YES"<<endl;
cout<<ans1+<<endl;
}
else
cout<<"NO"<<endl;
return ;
}

Gym 100971C 水&愚&三角形的更多相关文章

  1. Gym 100989F 水&愚&vector

    standard input/output You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the che ...

  2. Gym 100971B 水&愚

    Description standard input/output Announcement   Statements A permutation of n numbers is a sequence ...

  3. UESTC 2016 Summer Training #1 Div.2

    最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...

  4. I - Cows

    来源 poj 3348 Your friend to the south is interested in building fences and turning plowshares into sw ...

  5. Poj2826 An Easy Problem

    呵呵哒.WA了无数次,一开始想的办法最终发现都有缺陷.首先需要知道: 1)线段不相交,一定面积为0 2)有一条线段与X轴平行,面积一定为0 3)线段相交,但是能接水的三角形上面线段把下面的线段完全覆盖 ...

  6. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  7. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  8. codeforces Gym 100187H H. Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  9. Codeforces gym 100685 C. Cinderella 水题

    C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C ...

随机推荐

  1. pytho线程信号量

    pytho线程信号量 import threading,time def going(num,sleep_time): semaphore.acquire()#启动允许执行 print("g ...

  2. WPF中对XML的读写

    XML(可扩展标记语言) 定义:用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 写操作: XmlTextWriter wri ...

  3. WP Mail SMTP插件解决Contact Form 7表单提交失败问题

    WP Mail SMTP插件解决Contact Form 7表单提交失败问题 WP Mail SMTP是一款非常优秀的解决WordPress主机因为不支持或者是禁用了mail()函数,导致无法实现在线 ...

  4. jfinal excel表导出

    在自己的WEB项目中要用到导出Excel,所以结合网络上的资源写了一个自己的export 工具类. 说明: JFinal 环境 WEB项目 JAVA后台生成非JS插件 好了,直接撸代码 1.设置文件保 ...

  5. 分享一个漂亮按钮插件FancyButtons

    一转眼,2018年的第10天就这样过去了.回看17年,曾经做了些啥都忘记了,就像每一天写日志时的样子(双手放在键盘上,怒着嘴,抬着头,望着天花板), 然后突然记得好像好久没有写随笔了(@_@).自从配 ...

  6. 配置管理-SpringCloudConfig

    1.搭建配置管理服务 添加依赖 <dependencies> <dependency> <groupId>org.springframework.cloud< ...

  7. Nginx http重定向到https时,post请求变为get的问题

    Http协议是有状态码的,比较熟悉的状态码是200,代表链接OK,还有404和403,一个是not found,另一个是forbidden.Not found不用多说,可能是地址栏输入有误,或者是网页 ...

  8. HDwiki 源代码 - 互动百科开源

    昨日3.15,在曝光的企业中出现了一家让我好奇的企业(互动百科),一直不敢想百科能独立出来做成一家公司.出于对网站的好奇,今日进入该网站,惊讶的是此公司已经上市(股票代码:835799),在网站的底部 ...

  9. ecshop里操作session与cookie

    目录 操作session 操作cookie html模板里提交保存用用户名 php里 js里保存cookie js里读取cookie html模板里smart的保留变量 html模板里取session ...

  10. Android 停止调试程序

    现在我知道怎么停掉debug的Android程序了,很简单,进入ddms界面,对着你的进程,kill.