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. Android入门(九)文件存储与SharedPreferences存储
  2. apache php 工作模式,PHP Apache中两种工作方式区别(CGI模式、Apache 模块DLL)
  3. Unity Optimizing Shader Load Time
  4. Debenham养老金项目关键流程1-员工分类流程
  5. kickstart无人值守自动安装操作系统
  6. IDEA常用快捷键总结
  7. centos下修改mysql默认端口
  8. 金融理财软件测试项目,大学生创新创业大赛金融理财项目创业计划书18-23-879(15页)-原创力文档...
  9. Android获取下载文件名称及类型
  10. 大型复杂群体项目分解结构(PBS)概念与方法研究
  11. 联通查询套餐及名下联通卡
  12. 生鲜配送APP软件开发快速制作
  13. ubuntu 修改系统默认语言为英文!
  14. python: 解决SyntaxError: encoding problem
  15. 【业务架构】获得正确业务能力的 12 项必备措施
  16. bulk interface驱动_Linux 驱动架构简析
  17. 肝素修饰载玻片/生物芯片(Heparin Functional Glass Slides)
  18. Python 图形界面框架 PySide6 使用及避坑指南
  19. java笔试题50道 收藏版
  20. MySQL的左连接、右连接、内连接

热门文章

  1. IT互联网行业应届生求职杂谈
  2. The Twenty-fourth Of Word-Day
  3. 找回家中宽带PPPoE账号密码
  4. 干货 | 18个Python爬虫实战案例(已开源)
  5. 简单聊聊煤炭行业的数字化和可持续发展
  6. 《小说朗读器》新增功能
  7. android5.1谷歌下载,谷歌发布Android 5.1源代码
  8. 一图看懂RISC-V星光板(VisionFive)的启动流程
  9. 【vue3+ts后台管理】用户列表查询、编辑
  10. 基于Android的网上选课app