rt,芝士代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=114514;
int a[maxn];
long long sum,n;
queue <long long> q1;
queue <long long> q2;
int red(){
int as=0;int fl=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')fl=-1;ch=getchar();}
while(isdigit(ch)){as=as*10+ch-'0';ch=getchar();}
return as*fl;
}
int main(){
n=red();
for(int i=1;i<=n;i++){
int m;
m=red();
a[m]++;
}
for(int i=1;i<=100000;i++){
while(a[i]){
a[i]--;
q1.push(i);
}
}
sum=0;
for(int i=1;i<=n-1;i++){
int x,y;
if((q1.front()<q2.front()&&!q1.empty())||q2.empty()){
x=q1.front();
q1.pop();
}
else{
x=q2.front();
q2.pop();
}
if((q1.front()<q2.front()&&!q1.empty())||q2.empty()){
y=q1.front();
q1.pop();
}
else{
y=q2.front();
q2.pop();
}
sum+=x+y;
q2.push(x+y);
}
printf("%lld",sum);
return 0;
}
先是自己做了10分,看了题解改了改判定30分,又从改成了桶排序结果还是30,哭了。。。(现在我都感觉我的代码和题解一样了)