乙级的难度,没啥说的。注意初始化值,不然IDE过了(可能都是赋值为0)pat过不了。
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n, a, s1 = 0, s2 = 0;
scanf ("%d", &n);
for (int i = 0; i < n; i++) {
scanf ("%d", &a);
v.push_back(a);
}
sort (v.begin(), v.end());
for (int i = 0; i < v.size() / 2; i++)
s1 += v[i];
for (int i = v.size() / 2; i < v.size(); i++)
s2 += v[i];
if (v.size() % 2 == 0)
cout << "0 ";
else
cout << "1 ";
cout << abs(s1 - s2);
}