Last active
December 16, 2015 13:58
-
-
Save soulmachine/5445052 to your computer and use it in GitHub Desktop.
POJ 3253 - Fence Repair,http://poj.org/problem?id=3253
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// POJ 3253 - Fence Repair,http://poj.org/problem?id=3253 | |
#include <iostream> | |
#include <queue> | |
#include <algorithm> | |
#include <functional> | |
using namespace std; | |
typedef long long int64; | |
int main() { | |
int n; | |
priority_queue<int64,vector<int64>, greater<int64> > q; | |
int64 len; | |
int64 total=0; | |
cin >> n; | |
while(n > 0) { | |
--n; | |
cin >> len; | |
q.push(len); | |
} | |
while(q.size()>1) { | |
const int64 a = q.top(); | |
q.pop(); | |
const int64 b = q.top(); | |
q.pop(); | |
total += (a+b); | |
q.push(a+b); | |
} | |
cout << total << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment