60 TLESubtask #4
查看原帖
60 TLESubtask #4
947863
SHC_CENSORED楼主2024/7/12 07:50
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
priority_queue<int,vector<int>,greater<int> > q;
int n,m,sum;
inline int read(){
   register int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
   return s*w;
}
inline void print(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0); 
	n=read();
	for(int i=1;i<=n;i++){
		m=read();
		q.push(m);
	}
	while(q.size()>1){
		int x=q.top();
		q.pop();
		int y=q.top();
		q.pop();
		q.push(x+y);
		sum=sum+x+y;
	}print(sum);
	return 0;
}
2024/7/12 07:50
加载中...