# The Smallest Pair | CodeChef Solution

Hello coders, today we are going to solve The Smallest Pair CodeChef Solution whose Problem Code is SMPAIR.

You are given a sequenceÂ a1, a2, …, aN. Find the smallest possible value ofÂ aiÂ + aj, where 1 â‰¤Â iÂ <Â jÂ â‰¤Â N.

## Input Format

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each description consists of a single integer N.

The second line of each description containsÂ NÂ space separated integers –Â a1, a2, …, aNÂ respectively.

## Output Format

For each test case, output a single line containing a single integer – the smallest possible sum for the corresponding test case.

## Constraints

• TÂ =Â 105,Â NÂ =Â 2Â : 13 points.
• TÂ =Â 105,Â 2Â â‰¤Â NÂ â‰¤Â 10Â : 16 points.
• TÂ =Â 1000,Â 2Â â‰¤Â NÂ â‰¤Â 100Â : 31 points.
• TÂ =Â 10,Â 2Â â‰¤Â NÂ â‰¤Â 105Â : 40 points.
• 1Â â‰¤Â aiÂ â‰¤Â 106

Example

Sample Input

``````1
4
5 1 3 4
``````

Sample Output

``4``

Explanation

Here we pickÂ a2Â andÂ a3. Their sum equals to 1 + 3 = 4.

## Solution – The Smallest Pair | CodeChef Solution

### C++

```#include<bits/stdc++.h>
using namespace std;

int main() {
int n;
cin>>n;
while(n--){
int m;
cin>>m;
int a[m];

for(int i=0;i<m;i++){
cin>>a[i];
}

sort(a,a+m);
cout<<a[0]+a[1]<<endl;
}
return 0;
}
```

### Python

```#Solution Provided by CodingBroz
T = int(input())
for i in range(T):
n = int(input())
s = list(map(int, input().split()))
s.sort()
print(s[0] + s[1])```

### Java

```import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int a;
int m1, m2;

while(t-- > 0) {
int n = sc.nextInt();
m1 = Integer.MAX_VALUE;
m2=Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
a = sc.nextInt();
if(a < m1) {
m2 = m1;
m1 = a;
} else if(a >= m1 && a < m2) {
m2 = a;
}
}
System.out.println(m1 + m2);
}

sc.close();
}
}
```

Disclaimer: The above Problem (The Smallest Pair) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.