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. 格式化测试数据,组装用于插入表中的sql语句
  2. 参加Tech.Ed 2006北京行
  3. LeapFTP 注册码
  4. 个人信息管理系统代码_Thymeleaf+SpringBoot+Mybatis实现的易游网旅游信息管理系统...
  5. xlwings 合并单元格 读取_xlwings,让excel飞起来
  6. css矩形凹陷效果_被低估的CSS滤镜:drop-shadow
  7. lua面向对象封装及元表(metatable)性能测试
  8. php多表条件查询,php如何实现多表查询
  9. 在线假单词随机生成器
  10. SpringMVC实现list表单(六)
  11. 1.Kettle下载与安装
  12. Oracle的云计算模式
  13. free、detele与野指针
  14. errpt and errclear are unnormal
  15. ubuntu18.04安装pcl库
  16. facsum (线性筛 积性函数)
  17. 数据库课程设计矿大_管理信息系统课程设计样本.pdf
  18. TexturePacker命令行拉起参数
  19. Swift学习笔记-1
  20. 计算机自动控制论文,精选:计算机在自动控制技术实践中的应用分析论文原稿...

热门文章

  1. 使用JAVA编写报文接收端的注意事项
  2. Python新手入门英文词汇笔记(1-1)
  3. NDK OpenGL ES 3.0 开发(二十):3D 模型
  4. 【技术君啃书之旅】web安全之机器学习入门 第五章笔记
  5. BUGKU easypicture
  6. 成考高起专要参加英语计算机统考吗,2020年成人高考高起专英语考试大纲科目...
  7. 【MQ】【day1】软件安装+MQ简介
  8. php中使用redis队列操作实例代码
  9. 了解redis队列原理
  10. 女人——一人之下(4季12话)