Created
October 12, 2019 15:33
-
-
Save surinoel/7820c0115a5035a03c10c24f645249ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <queue> | |
#include <vector> | |
#include <iostream> | |
#include <functional> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
priority_queue<int, vector<int>, greater<int>> pq; | |
int tc; | |
cin >> tc; | |
while (tc--) { | |
int x; | |
cin >> x; | |
pq.push(x); | |
} | |
int ans = 0; | |
while (pq.size() > 1) { | |
int a = pq.top(); | |
pq.pop(); | |
int b = pq.top(); | |
pq.pop(); | |
ans += (a + b); | |
pq.push(a + b); | |
} | |
cout << ans << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment