Iamtui1010

replacesum.cpp

Jan 12th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<iostream>
  2. #include<set>
  3. #include<cstdlib>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     //freopen("replacesum.inp", "r", stdin);
  13.     multiset<long> a;
  14.     long n, sum = 0, tim = 0;
  15.     cin >> n;
  16.     for (long i = 0; i < n; ++i)
  17.     {
  18.         long x;
  19.         cin >> x;
  20.         a.insert(x);
  21.         sum += x;
  22.     }
  23.     while (a.size() > 1)
  24.     {
  25.         long t = *a.begin();
  26.         a.erase(a.begin());
  27.         t += *a.begin();
  28.         a.erase(a.begin());
  29.         tim += t;
  30.         a.insert(t);
  31.     }
  32.     cout << sum << ' ' << tim << nln;
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment