forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB0030.cpp
More file actions
40 lines (36 loc) · 689 Bytes
/
B0030.cpp
File metadata and controls
40 lines (36 loc) · 689 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
36
37
38
39
40
// Problem Code: SMPAIR
#include <iostream>
#include <vector>
#include <limits>
using namespace std;
int smallestPair(vector<int> N){
int first, second;
first = second = numeric_limits<int>::max();
for(int i=0 ; i<N.size() ; i++){
if(N[i] < first){
second = first;
first = N[i];
}
else if(N[i] < second && N[i] != first)
second = N[i];
}
return first + second;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T, N, num;
vector<int> numbers;
cin >> T;
for(int i=1 ; i<=T ; i++){
cin >> N;
for(int j=0 ; j<N ; j++){
cin >> num;
numbers.push_back(num);
}
cout << smallestPair(numbers) << endl;
numbers.clear();
}
return 0;
}