codepage=1208,Codeforces 1189B Number Circle

 2023-10-07 阅读 14 评论 0

摘要:題目鏈接:http://codeforces.com/problemset/problem/1189/B codepage=1208,AC代碼: #include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int a[maxn]; int b[maxn]; int c[maxn]; bool check(int i) {if(a[i] &

題目鏈接:http://codeforces.com/problemset/problem/1189/B


codepage=1208,AC代碼:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int b[maxn];
int c[maxn];
bool check(int i)
{if(a[i] < a[i-1]+a[i+1]) return true;else return false;
}
int main()
{int n;cin >> n;for(int i = 0;i < n;i++){cin >> a[i];}sort(a,a+n);int b1 = 0,c1 = 0;for(int i = 0;i < n;i++){if(i%2 == 0) c[c1++] = a[i];else b[b1++] = a[i];}for(int i = 0;i < c1;i++){a[i] = c[i];}for(int i = c1;i < n;i++){a[i] = b[--b1];}bool flag = true;for(int i = 1;i < n-1;i++){if(!check(i)) flag = false;}if(!flag || a[n-1] >= a[0] + a[n-2] || a[0] >= a[n-1] + a[1]) cout << "NO";else{cout << "YES" << endl;for(int i = 0;i < n;i++){cout << a[i] << " ";}}return 0;
}

?

轉載于:https://www.cnblogs.com/Carered/p/11165875.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/125264.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息