Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- /// from HUNG MINE with love <3
- long long aa[200001], res = 0, n;
- priority_queue <long long, vector <long long>, greater <long long> > q;
- int main () {
- //freopen (".inp", "r", stdin);
- //freopen (".out", "w", stdout);
- ios_base :: sync_with_stdio (0);
- cin.tie (0);
- cout.tie (0);
- cin >> n;
- for (long long i = 1; i <= n; ++ i) {
- cin >> aa[i];
- q.push (aa[i]);
- }
- if (n % 2 == 0) {
- q.push (0);
- }
- while (q.size () > 1) {
- long long a = q.top ();
- q.pop ();
- long long b = q.top ();
- q.pop ();
- long long c = q.top ();
- q.pop ();
- res += (a + b + c);
- q.push (a + b + c);
- }
- cout << res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement