The Smallest Pair ||codechef||beginner solution ||programming info

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

Input

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

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

Constraints

  • T = 105N = 2 : 13 points.
  • T = 1052 ≤ N ≤ 10 : 16 points.
  • T = 10002 ≤ N ≤ 100 : 31 points.
  • T = 102 ≤ N ≤ 105 : 40 points.
  • 1 ≤ ai ≤ 106

Example

Input:
1
4
5 1 3 4

Output:
4

Explanation

Here we pick a2 and a3. Their sum equals to 1 + 3 = 4.
SOLUTION USING C++ LANGUAGE:-
#include <bits/stdc++.h>
using namespace std;

int main() 
{
 int t,n;
 cin >>t;
 while(t--)
 {
 int i;
 cin>>n;
 int a[n];
 for(i=0;i<n;i++)
 {
  cin>>a[i];
 }
 sort(a,a+n);
 cout<<a[0]+a[1]<<"\n";
 }return 0;


Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support