大佬提供一下思路吧
#include<iostream>
#include<algorithm>
using namespace std;
long long n,sum;
long long a[100005];
bool cmp(int x,int y){
if(x>y){
return x>y;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
if(n<=2&&a[i]<a[i+1]){
sum+=a[i+1];
break;
}
else if(a[i]>a[i+1]&&n<=2){
sum+=a[i];
break;
}
else if(n!=2&&a[i]<a[i+1]){
if(a[i+1]==true){
break;
}
sum+=a[i+1];
a[i+1]==true;
}
else if(n!=2&&a[i]>a[i+1]){
if(a[i]==true){
break;
}
sum+=a[i];
a[i]==true;
}
}
cout<<sum;
return 0;
}