-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0008.cpp
More file actions
35 lines (31 loc) · 687 Bytes
/
E0008.cpp
File metadata and controls
35 lines (31 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
Problem Statement: https://www.hackerrank.com/challenges/mini-max-sum/problem
*/
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
void miniMaxSum(vector<int> arr) {
int min,max;
min = max = arr[0];
for(int i=0 ; i<arr.size() ; i++){
if(min > arr[i])
min = arr[i];
else if(max < arr[i])
max = arr[i];
}
long long minSum = accumulate(arr.begin(), arr.end(), (long long)0) - max;
long long maxSum = accumulate(arr.begin(), arr.end(), (long long)0) - min;
printf("%lld %lld\n",minSum,maxSum);
}
int main()
{
int num,len=5;
vector<int> arr;
for(int i=0 ; i<len ; i++){
cin>>num;
arr.push_back(num);
}
miniMaxSum(arr);
return 0;
}