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. XML格式与实体类的转换

    背景 本人头一回写博客,请大家多多关照.通过读取XML文件获取用户管理权限,其中涉及三部分: 1.XML文件的生成: 2.XML文件的读取: 3.XML文件的保存: 如何做 第一步:自己先将XML文件 ...

  2. Vue入门之v-if的使用

    在vue中一些常用的指令都是v-这样的,v-if是vue的一个内部指令,常用于html中 代码 <!DOCTYPE html> html lang="en"> & ...

  3. 十二、MySQL 查询数据

    MySQL 查询数据 MySQL 数据库使用SQL SELECT语句来查询数据. 你可以通过 mysql> 命令提示窗口中在数据库中查询数据,或者通过PHP脚本来查询数据. 语法 以下为在MyS ...

  4. ASP.NET Core模块化前后端分离快速开发框架介绍之3、数据访问模块介绍

    源码 GitHub:https://github.com/iamoldli/NetModular 演示地址 地址:https://nm.iamoldli.com 账户:admin 密码:admin 前 ...

  5. 【CodeBase】通过层级键在多维数组中获取目标值

    通过层级键在多维数组中获取目标值 /* *Author : @YunGaZeon *Date : 2017.08.09 *param data : Data Array *param keys : K ...

  6. C++实例 MySTLString

    #include <iostream> #include <cstring> #include <string> using namespace std; clas ...

  7. [bzoj1912]异象石(set)

    Description Adera是Microsoft应用商店中的一款解谜游戏. 异象石是进入Adera中异时空的引导物,在Adera的异时空中有一张地图.这张地图上有N个点,有N-1条双向边把它们连 ...

  8. mysql 分类

    一.系统变量 说明:变量由系统提供,不用自定义 语法: 1.查看系统变量 show[global | session]varisables like ‘ ’:如果没有显示声明global 还是sess ...

  9. System.AccessViolationException”类型的第一次机会异常在 System.Data.dll 中发生 其他信息: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

    管理员cmd中运行  netsh winsock reset

  10. UNIX 系统中 wc 程序的主要部分

    以下代码为 UNIX 系统中 wc 程序的骨干部分 #include <stdio.h> #define IN 1 #define OUT 0 int main(int argc, cha ...