Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cmath>
- #include <queue>
- #include <stack>
- #include <algorithm>
- #include <map>
- #include <iomanip>
- #include <set>
- #include <unordered_set>
- #include <ctime>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- //#define HOME
- void jakos() {
- #ifdef HOME
- freopen("in.txt", "r", stdin);
- //freopen("out.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- }
- #define int long long
- typedef long long ll;
- const int mod = 1e9 + 7;
- const int base = 179;
- const int INF = 1e9;
- const int N = 1e7;
- int search(ll x, vector<ll> & b) {
- int l = 0;
- int r = b.size() - 1;
- while (l + 1 < r) {
- int m = l + (r - l) / 2;
- if (b[m] <= x) {
- l = m;
- }
- else {
- r = m;
- }
- }
- return l;
- }
- signed main() {
- jakos();
- int n;
- cin >> n;
- multiset<int> a;
- for (int i = 0; i < n; i++) {
- int tmp;
- cin >> tmp;
- a.insert(tmp);
- }
- int ans = 0;
- while (a.size() > 1) {
- int f = *a.begin();
- a.erase(a.begin());
- int s = *a.begin();
- a.erase(a.begin());
- int res = f + s;
- ans += res;
- a.insert(res);
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement