首页 > 其他 > 详细

A. Ehab Fails to Be Thanos

时间:2019-06-04 13:44:55      阅读:249      评论:0      收藏:0      [点我收藏+]

链接:https://codeforces.com/contest/1174/problem/A

题意:

You‘re given an array aa of length 2n2n. Is it possible to reorder it in such way so that the sum of the first nn elements isn‘t equal to the sum of the last nn elements?

思路:

排序后求前一半和后一半的和比较。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;

int a[2010];

int main()
{
    cin >> n;
    for (int i = 1;i <= 2*n;i++)
        cin >> a[i];
    sort(a+1, a+1+2*n);
    if (accumulate(a+1, a+1+n, 0) == accumulate(a+n+1, a+1+2*n, 0))
        cout << -1 << endl;
    else
    {
        for (int i = 1; i <= 2 * n; i++)
            cout << a[i] << ‘ ‘;
        cout << endl;
    }

    return 0;
}

  

A. Ehab Fails to Be Thanos

原文:https://www.cnblogs.com/YDDDD/p/10972855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!