居然和BZOJ 1724完全一样o(╯□╰)o
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; priority_queue<int,vector<int>,greater<int> > q; inline int read() { char ch; int num,f=0; while(!isdigit(ch=getchar())) f|=(num=='-'); num=ch-'0'; while(isdigit(ch=getchar())) num=num*10+ch-'0'; return f?-num:num; } int main() { n=read(); for(int i=1;i<=n;i++) { int x=read(); q.push(x); } if(n==1){cout << q.top();return 0;} ll res=0; while(q.size()>1) { int x=q.top();q.pop(); int y=q.top();q.pop(); res+=(x+y); q.push(x+y); } cout << res; return 0; }