【POJ3253】Fence Repair

problem

solution

codes

#include<iostream>  
#include<cstdio>  
#include<queue>  
using namespace std;  

int l[20005];  

int main()  {  
    int n;
    while(cin>>n){  
        for(int i = 0;i < n; i++)cin>>l[i]; 
        priority_queue<int, vector<int>, greater<int> > q;  
        for(int i = 0; i < n; i++)q.push(l[i]);  
        long long ans = 0;
        while(q.size()>1){
            int a = q.top(); q.pop();  
            int b = q.top(); q.pop();  
            ans += (a+b);  
            q.push(a+b);  
        }  
        cout<<ans<<"
";
    }  
    return 0;  
}
原文地址:https://www.cnblogs.com/gwj1314/p/9444800.html