Skip to content

Instantly share code, notes, and snippets.

@soulmachine
Last active December 16, 2015 13:58
Show Gist options
  • Save soulmachine/5445052 to your computer and use it in GitHub Desktop.
Save soulmachine/5445052 to your computer and use it in GitHub Desktop.
POJ 3253 - Fence Repair,http://poj.org/problem?id=3253
// 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