Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <algorithm>
  8. #include <map>
  9. #include <iomanip>
  10. #include <set>
  11. #include <unordered_set>
  12. #include <ctime>
  13. #include <cstdlib>
  14. #include <cstring>
  15.  
  16. using namespace std;
  17.  
  18. //#define HOME
  19. void jakos() {
  20. #ifdef HOME
  21.     freopen("in.txt", "r", stdin);
  22.     //freopen("out.txt", "w", stdout);
  23. #endif
  24.     ios_base::sync_with_stdio(false);
  25.     cin.tie(0);
  26. }
  27.  
  28. #define int long long
  29. typedef long long ll;
  30.  
  31. const int mod = 1e9 + 7;
  32. const int base = 179;
  33. const int INF = 1e9;
  34. const int N = 1e7;
  35.  
  36. int search(ll x, vector<ll> & b) {
  37.     int l = 0;
  38.     int r = b.size() - 1;
  39.     while (l + 1 < r) {
  40.         int m = l + (r - l) / 2;
  41.         if (b[m] <= x) {
  42.             l = m;
  43.         }
  44.         else {
  45.             r = m;
  46.         }
  47.     }
  48.     return l;
  49. }
  50.  
  51. signed main() {
  52.     jakos();
  53.  
  54.     int n;
  55.     cin >> n;
  56.     multiset<int> a;
  57.     for (int i = 0; i < n; i++) {
  58.         int tmp;
  59.         cin >> tmp;
  60.         a.insert(tmp);
  61.     }
  62.     int ans = 0;
  63.     while (a.size() > 1) {
  64.         int f = *a.begin();
  65.         a.erase(a.begin());
  66.         int s = *a.begin();
  67.         a.erase(a.begin());
  68.         int res = f + s;
  69.         ans += res;
  70.         a.insert(res);
  71.     }
  72.  
  73.     cout << ans << endl;
  74.  
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement