题解
2024-03-27 21:13:54
发布于:河北
7阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int a[n+1];
for (int i=0;i<n;i++){
cin >> a[i];
}
sort(a,a+n,greater<int>());
a[n]=0;
int sum1=a[0];
for (int i=3;i<n;i=i+4){
sum1=sum1+a[i]+a[i+1];
}
int sum2=0;
for (int i=1;i<n;i=i+4){
sum2=sum2+a[i]+a[i+1];
}
int res;
res=sum1-sum2;
if (res>=0) cout << res << " ";
else cout << -res<< " ";
return 0;
}
这里空空如也
有帮助,赞一个