#include #include using namespace std; void partitionArray(int* a, int beg, int end, int* pivot) { int left = beg; //initially left point to the first element of the array int right = end; //initially right point to the last element of the array *pivot = left; //initially pivot point to first element of the array int tmp; //used for swapping values while(1) { //pivot pointing at left while(a[*pivot] <= a[right] && *pivot != right) //pivot element <= right element { right--; //move right one position towards left } if(*pivot == right) //both left and right pointing at same element of the array { break; }else if(a[*pivot] > a[right]) { //pivot element greater than right element. swap pivot and right element. tmp = a[right]; a[right] = a[*pivot]; a[*pivot] = tmp; *pivot = right; //pivot is now pointing to right } //pivot pointing to right while(a[*pivot] >= a[left] && *pivot != left) //pivot element >= left element { left++; //move left one position towards right } if(*pivot == left) //both left and right pointing at the same element of the array { break; }else if(a[*pivot] < a[left]) { //pivot element smaller than left element. swap pivot and left element. tmp = a[left]; a[left] = a[*pivot]; a[*pivot] = tmp; *pivot = left; //pivot is now pointing to left } } } void quickSort(int* a, int beg, int end) { int pivot; if(beg < end) { partitionArray(a, beg, end, &pivot); //this will find the pivot location and partition the array quickSort(a, beg, pivot - 1); //quick sort the left sub array quickSort(a, pivot + 1, end); //quick sort the right sub array } } int main(){ int n; cin >> n; int calories[n]; for(int calories_i = 0; calories_i < n; calories_i++){ cin >> calories[calories_i]; } quickSort(calories, 0, n-1); long int miles = 0; int j = 0; for(int calories_i = n-1; calories_i >= 0; calories_i--){ miles += calories[calories_i]*pow(2,j); j++; } cout<