https://codeforc.es/contest/1189/problem/B

优先考虑最大的元素怎么构造。拿两个次大的围着他就很好,但是其他的怎么安排呢?就直接降序排列就可以了。

a数组还开错了。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int n;
int a[100005]; int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
while(~scanf("%d", &n)) {
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
sort(a+1,a+1+n);
swap(a[n],a[n-1]); bool fail=false;
for(int i=2;i<=n-1;++i){
if(a[i]>=a[i-1]+a[i+1])
fail=true;
}
if(a[1]>=a[n]+a[2])
fail=true;
if(a[n]>=a[n-1]+a[1])
fail=true;
if(fail)
puts("NO");
else{
puts("YES");
for(int i=1;i<=n;++i){
printf("%d%c",a[i]," \n"[i==n]);
}
}
}
}

Codeforces - 1189B - Number Circle - 贪心的更多相关文章

  1. Codeforces 1189B Number Circle

    题目链接:http://codeforces.com/problemset/problem/1189/B AC代码: #include<bits/stdc++.h> using names ...

  2. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  3. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

  4. Codeforces C. Split a Number(贪心大数运算)

    题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output ...

  5. Codeforces 980E The Number Games 贪心 倍增表

    原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...

  6. Codeforces 980E The Number Games - 贪心 - 树状数组

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定一颗有$n$个点的树,$i$号点的权值是$2^{i}$要求删去$k$个点,使得剩下的点仍然连通,并且总权值和最大,问删去的所有点的编号. ...

  7. Codeforces 346C Number Transformation II 贪心(复杂度计算)

    题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的.我们考虑两种极端数据: ...

  8. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

  9. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

随机推荐

  1. 全局解释锁GIL

    ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native th ...

  2. linux机器间建立信任关系

    linux机器间建立信任关系 如何建立信任关系 在shell脚本中,需要使用scp命令将本地的文件复制到另一台机器中备份.但通常执行scp命令后都需要输入用户密码,这样在定时自动执行shell脚本中就 ...

  3. substring c# js java

    c# String.SubString(int index,int length) String.SubString(int start) 等效于 javascript stringObject.su ...

  4. shell getopts用法详解

    本文链接:https://blog.csdn.net/u012703795/article/details/46124519 获取UNIX类型的选项: unix有一个优点就是标准UNIX命令在执行时都 ...

  5. 设置div 居中 和得到dom元素高度

    javascript中获取dom元素高度和宽度的方法如下: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网 ...

  6. 3.xml的解析

    1.xml的解析原理简介(xml是标记型文档) (1)js使用dom解析标记型文档(html)? - 根据html的层级结构,在内存中分配一个树形结构,把html的标签,属性和文本都封装成对象 - d ...

  7. Zabbix分布式监控系统实践 自定义配置

    https://www.zabbix.com/wiki/templates/start 环境介绍OS: Ubuntu 10.10 Server 64-bitServers:zabbix-server: ...

  8. Linux g++ 编译添加 pthread

    If you are going to compile a C program with pthread.h in LINUX using GCC or G++ you will have to us ...

  9. LeetCode--044--通配符匹配(java)*

    给定一个字符串 (s) 和一个字符模式 (p) ,实现一个支持 '?' 和 '*' 的通配符匹配. '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个字符串完全匹配才算 ...

  10. Python3及Pycharm安装

    1.首先去python官网下载相应版本的Python安装包.如下: 2.下载完成后解压,双击exe文件进行安装,看到如下界面:Install Now表示默认安装:Customize installat ...