You are given nn numbers a1,a2,…,ana1,a2,…,an. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors?

给定了n个数,a1...an。是否存在一种排列方式使得每个数比与他相邻的两个数的和小?

For example, for the array [1,4,5,6,7,8][1,4,5,6,7,8], the arrangement on the left is valid, while arrangement on the right is not, as 5≥4+15≥4+1 and 8>1+68>1+6.

比如说,对于这个数列,左侧排列是可以的,右侧排列是不行的

Input

The first line contains a single integer nn (3≤n≤1053≤n≤105) — the number of numbers.

第一行包含一个整数n——数字的个数

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the numbers. The given numbers are not necessarily distinct (i.e. duplicates are allowed).

第二行包含n个整数——这些数字。给定的数字并不是绝对不同的(也就是说相同的数字也是可以的)

Output

If there is no solution, output "NO" in the first line.

如果没有答案,直接输出NO

If there is a solution, output "YES" in the first line. In the second line output nn numbers — elements of the array in the order they will stay in the circle. The first and the last element you output are considered neighbors in the circle. If there are multiple solutions, output any of them. You can print the circle starting with any element.

如果有一个解决方案,在第一行输出YES。第二行输出任何一个可行的方案。

Examples

input

Copy

3
2 4 3

output

Copy

YES
4 2 3 

input

Copy

5
1 2 3 4 4

output

Copy

YES
4 4 2 1 3

input

Copy

3
13 8 5

output

Copy

NO

input

Copy

4
1 10 100 1000

output

Copy

NO

Note

One of the possible arrangements is shown in the first example:

4<2+34<2+3;

2<4+32<4+3;

3<4+23<4+2.

One of the possible arrangements is shown in the second example.

No matter how we arrange 13,8,513,8,5 in a circle in the third example, 1313 will have 88 and 55 as neighbors, but 13≥8+513≥8+5.

There is no solution in the fourth example.

这个题的核心也是一个IDEA:对于“一般的排序”(逆序或顺序),这个序列早已满足了所谓“两边之和大于中间”的需求。比如说有序的序列1 2 3 4 5,2比1+3小,3比2+4小。这也就是说直接对原序列进行排列就可以得到一个解决方案,但是,这还得满足一个条件。

比如对于序列1 2 3 4 5 6,将他连成一个圈就是1 2 3 4 5 6 1,而6=1+5,并不满足条件。换句话说,你得让两端的连接点和它两端的元素满足题设条件。我们可以假设这个连接点为任何元素。假设它是b(n)元素,并且有显然的b(n-1)+b(n-2)>b(n),那么b(n)就可以当做一个连接点,把b(n-1)放在左侧,把b(n-2)放在右侧,由于数列有序,所以b(n-3)+b(n-1)>b(n-2)成立,以此类推到最后一个元素。b(n)b(n-2)  1,由于b(n)显然大于b(n-2),所以这一小节依然成立。所以全体数列符合题意。

所以思路如下:

  1. 对数组进行排序,并进行判断。
//#include<pch.h>
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf("%lld", &a)
#define println(a) printf("%lld\n", a)
#define reset(a, b) memset(a, b, sizeof(a))
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1000000007;
const int tool_const = 19991126;
const int tool_const2 = 33;
inline ll lldcin()
{ll tmp = 0, si = 1;char c;c = getchar();while (c > '9' || c < '0'){if (c == '-')si = -1;c = getchar();}while (c >= '0' && c <= '9'){tmp = tmp * 10 + c - '0';c = getchar();}return si * tmp;
}
///Untersee Boot IXD2(1942)
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
/**Last Remote**/
const int MAX = 3e5;
ll a[MAX];
int DETERMINATION()
{ll n;cin >> n;for (int i = 1; i <= n; i++)cin >> a[i];sort(a + 1, a + n + 1);if (a[n - 1] + a[n - 2] <= a[n])//不满足条件{cout << "NO" << endl;}else{cout << "YES" << endl;for (int i = 1; i <= n - 3; i++)cout << a[i] << " ";cout << a[n - 1] << " " << a[n] << " " << a[n-2] << endl;}       return 0;
}

CF1189B Number Circle(数字圈)相关推荐

  1. 中英翻译《The number thirteen数字13》

    The number thirteen 数字13 一.Pre-reading activity 阅前思考 1.Do you have a lucky number? If so, what is it ...

  2. C语言判断是否为happy number快乐数字的算法(附完整源码)

    C语言判断是否为happy number快乐数字的算法 C语言判断是否为happy number快乐数字的算法完整源码(定义,实现,main函数测试) C语言判断是否为happy number快乐数字 ...

  3. J9数字论:数字圈的FOMO现象该如何杜绝?

    FOMO(fear of missing out),中文意思是害怕错过,我第一次了解FOMO这个词是在web3领域,它是一个数字圈常用词,在看到别人赚钱,我们容易产生FOMO情绪,尤其是在数字市场这种 ...

  4. sql科学计数法转换为普通数字_一张图读懂Python3的Number(数字)类型

    新朋友请点上方"数据分析师攻略"加关注 Number(数字)是Python3六个标准的数据类型中其中一种,它是一种不可变数据,分别有整型(int).浮点型(float).布尔型(b ...

  5. html5number最小值,JavaScript Number(数字)

    JavaScript 只有一种数字类型. 可以使用也可以不使用小数点来书写数字. JavaScript 数字 JavaScript 数字可以使用也可以不使用小数点来书写: var pi=3.14; / ...

  6. 关于Oracle执行sql语句报错[ORA-01722: invalid number]无效数字解决思路

    一.问题提示 执行Oracle的sql语句提示[ORA-01722: invalid number]无效数字错误. 二.问题分析 2.1.类型不匹配 即数据库中字段的设计类型与插入.修改的类型不统一( ...

  7. CodeForces - 1189B Number Circle

    原题传送器<----点我 **题意:**n个数字,请你给它们排个序围成一个环,满足任意一个数两边的数之和大于它本身,例如题目给的图(左图为正确答案),如果不存在这样的环就输出NO. 难度★ 题解 ...

  8. 268. Missing Number(缺失数字)

    题目地址:https://leetcode.com/problems/missing-number/description/ Given an array containing n distinct ...

  9. Number Game(数字游戏)

    Number Game 爱丽丝和鲍勃正在玩游戏.它们具有正整数数组一个尺寸n. 在开始游戏之前,爱丽丝选择一个整数千≥0.游戏持续k阶段,阶段的编号从1自k.在我-th 阶段,Alice 必须从数组中 ...

最新文章

  1. Win32 环境下的堆栈
  2. linux 下jdk的卸载与安装
  3. 中国证券期货业南方信息技术中心二期约1.5万个机柜建设项目EPC总包定了!
  4. spring部分注解
  5. linux 内存管理优化,Linux性能优化实战 内存篇 阅读笔记
  6. 普通筛法时间界的证明
  7. 蓝桥杯---2012--比酒量(暴力)
  8. SQL语言:DQL,DML,DDL,DCL
  9. Spark、Strom、Flink和Beam的技术选型
  10. Matlab高尔顿板仿真模拟实验
  11. Linux 系统硬盘MBR转换为GPT格式并扩容
  12. 树莓派开发—语音识别功能
  13. 张驰咨询:关于企业选择六西格玛绿带培训人员,你需要知道这些
  14. 西瓜书学习笔记(2)——模型评估与选择
  15. Java线程池「异常处理」正确姿势:有病就得治
  16. 最佳论文!商汤提出手机端实时单目三维重建系统 | ISMAR 2020
  17. C#实现生产者与消费者关系
  18. 面试自我介绍如何介绍呢?
  19. 长期连载_ [置顶]马浩然(AH)语录或机房日常[学习无关]
  20. C语言求最大公约数问题分析(含代码分享)

热门文章

  1. 我的网络流sap,isap,dinic三种方法的对比总结
  2. web常见页面错误代码及解决办法
  3. 最新数据处理 之 1:100万与1:25万全国基础地理数据库批量合并
  4. 联想凌拓:谁更如愿以偿呢?
  5. C/S和BS两种开发模型
  6. mysql unixtime 毫秒_MySQL的FROM_UNIXTIME()和UNIX_TIMESTAMP()函数的区别
  7. win10如何查看计算机当前用户名,win10系统中的用户名是什么?在哪里看
  8. 鸡尾酒排序(Cocktail sort)
  9. EBSD的具体功能及样品制备
  10. 【学习笔记】广和通4G模块-MC615学习笔记