#include<bits/stdc++.h> using namespace std; priority_queue<int, vector<int>, greater<int> > L; int main () { int N, m, i, sum = 0; cin>>N; for ( i = 0 ;i < N ; i ++) { cin>>m; L.push(m); } while ( L.size() > 1 ) { int min1, min2; min1 = L.top(); L.pop(); min2 = L.top(); L.pop(); sum += (min1 + min2); L.push(min1 +min2); } cout<<sum; return 0; }
by: 发表于:2017-12-13 10:32:59 顶(0) | 踩(0) 回复
??
回复评论