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<long> 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
Plus Minus
You are viewing a single comment's thread. Return to all comments →
include
<iostream>
include
<vector>
include
<algorithm>
// For std::sortvoid miniMaxSum(const std::vector
<long>
& arr) { // Sort the array std::vector<long
> nums = arr; std::sort(nums.begin(), nums.end());}
int main() { std::vector<
long
> arr(5); for (int i = 0; i < 5; ++i) { std::cin >> arr[i]; }}