标签:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; int N,R; int x[50100]; int main() { #ifdef xxz freopen("in.txt","r",stdin); #endif // xxz ios::sync_with_stdio(false); cin.tie(0); while(cin>>N) { priority_queue<int,vector<int>,greater<int> > P; for(int i = 0; i < N; i++) { cin>>x[i]; P.push(x[i]); } long long ans = 0; while(P.size() > 1) { int L1 = P.top();P.pop(); int L2 = P.top();P.pop(); ans += L1+L2; P.push(L1+L2); } cout<<ans<<endl; } return 0; }
标签:
原文地址:http://blog.csdn.net/u013445530/article/details/43673353