Gym 100971C 水&愚&三角形

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

23 4

Output

YES2

Input

33 4 8

Output

YES6

Input

33 4 9

Output

NO
题意:给你一些边 判断是否存在一条边 使得和其中的任意两条边组合都能形成三角形 

题解:将边排序之后 所要添加的边存在上下界     ans1=a[n-1]-a[0];           ans2=a[0]+a[1];     范围内 任意输出

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n;
 4 int a[200005];
 5 int ans1,ans2;
 6 int main()
 7 {
 8     scanf("%d",&n);
 9     for(int i=0;i<n;i++)
10         scanf("%d",&a[i]);
11     sort(a,a+n);
12     ans1=a[n-1]-a[0];
13     ans2=a[0]+a[1];
14     if(ans1+1<ans2)
15     {
16         cout<<"YES"<<endl;
17         cout<<ans1+1<<endl;
18     }
19     else
20         cout<<"NO"<<endl;
21     return 0;
22 }
时间: 2024-10-14 20:48:06

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

Gym 100971B 水&amp;愚

Description standard input/output Announcement Statements A permutation of n numbers is a sequence of integers from 1 to n where each number is occurred exactly once. If a permutation p1, p2, ..., pn has an index i such that pi = i, this index is cal

Gym 100989F 水&amp;愚&amp;vector

standard input/output You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the cheaters in the Algorithms course. N students cheated and failed this semester and they all want to know who Mahone is in order to take revenge! Agent Ma

UESTC 2016 Summer Training #1 Div.2

最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria (B) 不会捉 Gym 100989E 水 Gym 100989F 水 Mission in Amman (B) 没看题 Queue (A) 感觉题意理解得有问题啊 1 #include <iostream> 2 #include <cstdio> 3 #include <cstr

ecjtu-summer training #4

Gym - 100952A 水题,看谁的时间少谁就赢了,不然就是平局. 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #define ll long long 5 using namespace std; 6 7 int main(){ 8 int n; 9 cin>>n; 10 while(n--){ 11 int h1,h2,m2,m1,s1,s2; 12 cin &

Poj2826 An Easy Problem

呵呵哒.WA了无数次,一开始想的办法最终发现都有缺陷.首先需要知道: 1)线段不相交,一定面积为0 2)有一条线段与X轴平行,面积一定为0 3)线段相交,但是能接水的三角形上面线段把下面的线段完全覆盖. (1),(2)的情况简单,主要是解决(3).下面对(3)进行讨论,如下图所示,设p1,p2是两线段各自位置较高的点,p0为两线段的交点,向量e是三角形p0p1p2的关于边p1p2的外侧法向量.则当e的终点位于第1,2象限时才会有积水,3,4象限是没有的.判断e的方向可以根据它与(p0p1+p0p

codeforces Gym 100187H H. Mysterious Photos 水题

H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/H Description Everyone probably heard the rumours about the constellation of Bermuda Triangle: any person who looks to this constellation of th

codeforces Gym 100187L L. Ministry of Truth 水题

L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description Andrey works in the Ministry of Truth. His work is changing articles in newspapers and magazines so that they praise the Party an

HDU 2091 空心三角形 --- 水题

/* HDU 2091 空心三角形 --- 水题 */ #include <cstdio> int main() { int kase = 0; char ch; int h, t; //h表示高 while (scanf("%c", &ch) == 1 && ch != '@'){ scanf("%d", &h); if (kase++){ printf("\n"); } getchar(); if

Codeforces gym 100685 C. Cinderella 水题

C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C Description Cinderella is given a task by her Stepmother before she is allowed to go to the Ball. There are N (1 ≤ N ≤ 1000) bottles with water in th