题目描述
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
C++ 代码
#include <iostream>
#include <cstring>
#include <numeric>
#include <algorithm>
using namespace std;
int main()
{
int n[100010], n1, x, p, nx, s1 = 0, s2 = 0;
cin >> n1;
for (int i = 0; i < n1; i++)
{
cin >> x;
n[i] = x;
}
sort(n, n + n1);
p = double(n1) / 2 + 0.5;
if (2 * p>n1)
{
nx = 1;
s1 = accumulate(n, n + p - 1, 0);
s2 = accumulate(n + p-1, n + n1, 0) ;
}
else
{
nx = 0;
s1 = accumulate(n, n + p, 0);
s2 = accumulate(n+p, n + n1, 0);
}
cout << nx << " " << s2 - s1;
return 0;
}