code
#include <stdio.h> void QuickSort(int *arr,int start,int end) { if (start >= end) return; int piv = start, left = start + 1, right = end, temp; while (left <= right) { while (left <= end && arr[left] <= arr[piv]) left++; while (right > start && arr[right] >= arr[piv]) right--; if (left > right) { temp = arr[right]; arr[right] = arr[piv]; arr[piv] = temp; } else { temp = arr[right]; arr[right] = arr[left]; arr[left] = temp; } } QuickSort(arr, start, right - 1); QuickSort(arr, right + 1, end); } int main() { int N, P[1000] = { 0 }, sum = 0, result = 0; scanf("%d", &N); for (int i = 0; i < N; i++) scanf("%d", &P[i]); QuickSort(P, 0, N - 1); for (int i = 0; i < N; i++) { sum = sum + P[i]; result += sum; } printf("%d", result); return 0; }