贪心
2024-07-03 09:28:17
发布于:湖南
35阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n;
int a[5010];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
sort(a + 1, a + n + 1);
int suma = 0, sumb = 0;
for (int i = n; i >= 1; i -- ) {
if (suma <= sumb) suma += a[i];
else sumb += a[i];
}
cout << abs(suma - sumb) << "\n";
}
这里空空如也
有帮助,赞一个