Plus Minus

  • + 0 comments

    include <iostream>

    include<vector>

    include <algorithm>// For std::sort

    void miniMaxSum(const std::vector<long>& arr) { // Sort the array std::vector<long> nums = arr; std::sort(nums.begin(), nums.end());

    // 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;
    

    }