代码如下,已经把思路注释出来了
#include<bits/stdc++.h>
using namespace std;
int a[20001];
int main(){
int n,poer=0;
cin>>n;
if(n==1){
int j;
cin>>j;
cout<<j;
return 0;
}
if(n==2){
int j1,j2;
cin>>j1>>j2;
cout<<j1+j2;
return 0;
}
for(int i=1;i<=n;i++){
int g;
cin>>g;
a[g]++;
}
int o=0,k=0,x,y;
for(int i=1;i<n;i++){
o=0;
while(o<=2){
if(a[++k]!=0){
o++;
if(o==1){
x=k;
}
else if(o==2){
y=k;
}
else{
poer=poer+x+y;
a[x+y]++;
a[x]--;
a[y]--;
k=x;
o=114514;
}
}
}
}
cout<<poer;
return 0;
}
在 C++里测试时正常输出
但一提交评测就全CE
求助大佬