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. ABBYY FineReader 14.0.107.232 Enterprise 下载和安装使用

    目录 1. 按 2. 软件功能 3. 软件特色 4. 安装说明 5. 激活说明 6. 下载地址 1. 按 ABBYY FineReader 是款功能强大的OCR文字识别软件:它支持者用户进行使用文档的 ...

  2. git上传文件夹的问题

    使用git上传文件夹一定要注意,文件夹里面至少有一个文件,因为git不能管理空文件夹 所以上传就会不成功

  3. Python日志库logging总结

    转自  https://cloud.tencent.com/developer/article/1354396 在部署项目时,不可能直接将所有的信息都输出到控制台中,我们可以将这些信息记录到日志文件中 ...

  4. 在PHPstorm上安装thinkPHP

    >环境:ubuntu php7.2 phpstorm https://blog.csdn.net/roukmanx/article/details/85646174 https://www.ka ...

  5. 图片公式转为word格式

    mathpix提取Latex格式,下载mathpix snipping tool工具,截图即可获取Latex格式公式 Latex格式去下面网站转换为mathml格式 https://johnmacfa ...

  6. 英语单词composing

    composing 来源——书籍Python.Crash.Course.2015.11 Using Individual Values from a List You can use individu ...

  7. 基于 Flink 的实时数仓生产实践

    数据仓库的建设是“数据智能”必不可少的一环,也是大规模数据应用中必然面临的挑战.在智能商业中,数据的结果代表了用户反馈.获取数据的及时性尤为重要.快速获取数据反馈能够帮助公司更快地做出决策,更好地进行 ...

  8. 暴力&打表

    _LH巨神好像不太会打表,这里来普及一下 还有暴力这么重要的东西网上讲的人竟然不多…… 一.打表 打表,就是针对一些输入数据比较小的题目的一种骗分技巧,当然有时候也可以在正解或暴力中起一定优化作用. ...

  9. Cluster基础(五):配置tracker、配置storage、文件测试及web访问

    一.配置tracker 目标: FastDFS是一个分布式文件系统,主要的服务器角色有Tracker和Storage.本例安装一台Tracker,实现以下功能: 接受客户端的访问 检索存储节点,为客户 ...

  10. C++ 得到系统时间

    Time::Time() {//得到系统时间 初始化 time_t t; t=time(NULL); tm *lt; lt=localtime(&t); hour=lt->tm_hour ...