fork(2) download
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <vector>
  6. #include <iostream>
  7. #include <set>
  8. #include <map>
  9. #define pb push_back
  10. #define bg begin
  11. #define ed end
  12. #define ins insert
  13. using namespace std;
  14.  
  15. typedef long long ll;
  16. typedef vector<int> vi;
  17. typedef vector<vi> vii;
  18.  
  19. ll p[300005], sums[300005];
  20.  
  21. int main ()
  22. {
  23. ll n;
  24. scanf ("%lld", &n);
  25. for (int i = 0; i < n; ++i)
  26. {
  27. scanf ("%lld", &p[i]);
  28. }
  29. sort (p, p + n);
  30. for (int i = 0; i < n; ++i)
  31. {
  32. if (!i)
  33. sums[i] = p[i];
  34. else
  35. sums[i] += p[i] + sums[i-1];
  36. }
  37. ll ans = 2LL*sums[n-1]; ll q = 0;
  38. for (ll q = 0; q < n-2; ++q)
  39. {
  40. ans += (sums[n-1]- p[q]);
  41. }
  42. printf ("%lld\n", ans);
  43. return 0;
  44. }
Runtime error #stdin #stdout 0s 8028KB
stdin
Standard input is empty
stdout
Standard output is empty