We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
// Calculate the minimum and maximum sums
long minSum = 0, maxSum = 0;
for (int i = 0; i < 4; i++) {
minSum += nums[i]; // Sum of the smallest 4 elements
maxSum += nums[i + 1]; // Sum of the largest 4 elements
}
std::cout << minSum << " " << maxSum << std::endl;
}
int main() {
std::vector arr(5);
for (int i = 0; i < 5; ++i) {
std::cin >> arr[i];
}
miniMaxSum(arr);
return 0;
}
Cookie support is required to access HackerRank
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 →
include
include
include // For std::sort
void miniMaxSum(const std::vector& arr) { // Sort the array std::vector nums = arr; std::sort(nums.begin(), nums.end());
}
int main() { std::vector arr(5); for (int i = 0; i < 5; ++i) { std::cin >> arr[i]; }
}