fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main(void)
  7. {
  8. int n;
  9. int arr[1001];
  10. int result[1001];
  11. int sum;
  12.  
  13. cin >> n;
  14. for (int i = 0; i < n; i++) cin >> arr[i];
  15.  
  16. sort(arr, arr + n);
  17. sum = result[0] = arr[0];
  18. for (int i = 1; i < n; i++)
  19. {
  20. result[i] = result[i - 1] + arr[i];
  21. sum += result[i];
  22. }
  23. cout << sum;
  24. return 0;
  25. }
Success #stdin #stdout 0s 4732KB
stdin
5
3 1 4 3 2
stdout
32