Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<set>
- #include<cstdlib>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- //freopen("replacesum.inp", "r", stdin);
- multiset<long> a;
- long n, sum = 0, tim = 0;
- cin >> n;
- for (long i = 0; i < n; ++i)
- {
- long x;
- cin >> x;
- a.insert(x);
- sum += x;
- }
- while (a.size() > 1)
- {
- long t = *a.begin();
- a.erase(a.begin());
- t += *a.begin();
- a.erase(a.begin());
- tim += t;
- a.insert(t);
- }
- cout << sum << ' ' << tim << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment