标签:style blog color io os for sp div c
1 #include<stdio.h> 2 #include<iostream> 3 #include<string> 4 #include<string.h> 5 #include<algorithm> 6 #include<iomanip> 7 #include<vector> 8 #include<time.h> 9 #include<queue> 10 #include<stack> 11 #include<iterator> 12 #include<math.h> 13 #include<stdlib.h> 14 #include<limits.h> 15 //#define ONLINE_JUDGE 16 #define ll long long 17 18 using namespace std; 19 priority_queue <ll, vector<ll>, greater<ll> > Q; 20 #define N 500050 21 22 int main() 23 { 24 int n; 25 while(scanf("%d",&n)!=EOF){ 26 for(int i=0;i<n;i++){ 27 int t; 28 scanf("%d",&t); 29 Q.push(t); 30 } 31 if(Q.size() > 1){ 32 ll num = 0; 33 while(Q.size()>1){ 34 ll n = Q.top();Q.pop(); 35 ll m = Q.top();Q.pop(); 36 num += (n+m); 37 Q.push(n+m); 38 } 39 printf("%lld\n",num); 40 }else{ 41 int t = Q.top(); 42 printf("%d\n",t); 43 } 44 } 45 return 0; 46 }
标签:style blog color io os for sp div c
原文地址:http://www.cnblogs.com/songacm/p/4004927.html