fork download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. #include <set>
  7. #include <map>
  8. #include <stack>
  9. #include <cstdio>
  10. #include <random>
  11. #include <queue>
  12. #include <deque>
  13.  
  14.  
  15. using namespace std;
  16.  
  17. //ifstream cin("input.txt");
  18. //ofstream cout("output.txt");
  19.  
  20. #define x first
  21. #define y second
  22. #define mp make_pair
  23. #define endl '\n'
  24.  
  25. typedef long long li;
  26. typedef double ld;
  27. typedef pair<int, int> pii;
  28. typedef pair<long long, long long> pll;
  29. typedef pair<pii, pii> ppp;
  30. typedef pair<pll, pll> ppl;
  31.  
  32. const int LIM = 1e5;
  33. const int INF = 1e9;
  34. const long long INF64 = 1e18;
  35. const int MOD = INF + 7;
  36. const double EPS = 1e-9;
  37.  
  38. int main() {
  39. ios_base::sync_with_stdio(false);
  40.  
  41. //freopen("input.txt", "r", stdin);
  42. //freopen("output.txt", "w", stdout);
  43.  
  44. int n;
  45.  
  46. cin >> n;
  47.  
  48. multiset<li> a;
  49.  
  50. for (int i = 0; i < n; i++) {
  51. li x_;
  52.  
  53. cin >> x_;
  54.  
  55. a.insert(x_);
  56. }
  57.  
  58. li ans = 0;
  59.  
  60. while (a.size() != 1) {
  61. li num1 = *a.begin();
  62.  
  63. a.erase(a.begin());
  64.  
  65. li num2 = *a.begin();
  66.  
  67. a.erase(a.begin());
  68.  
  69. a.insert(num1 + num2);
  70. ans += num1 + num2;
  71. }
  72.  
  73. cout << ans;
  74.  
  75. system("pause");
  76. return 0;
  77. }
  78.  
  79.  
Success #stdin #stdout #stderr 0s 15768KB
stdin
Standard input is empty
stdout
7203462176923582080
stderr
sh: 1: pause: not found