You are viewing a single comment's thread. Return to all comments →
void miniMaxSum(vector arr) { int max = arr[0]; int min = arr[0]; long total = arr[0]; for(int i = 1; i < arr.size(); i++) { if(arr[i] > max) max = arr[i]; if(arr[i] < min) min = arr[i]; total += arr[i]; } cout << (total - max) << " "; cout << (total - min) << endl; }
Seems like cookies are disabled on this browser, please enable them to open this website
Mini-Max Sum
You are viewing a single comment's thread. Return to all comments →
void miniMaxSum(vector arr) { int max = arr[0]; int min = arr[0]; long total = arr[0]; for(int i = 1; i < arr.size(); i++) { if(arr[i] > max) max = arr[i]; if(arr[i] < min) min = arr[i]; total += arr[i]; } cout << (total - max) << " "; cout << (total - min) << endl; }