Skip to content

Instantly share code, notes, and snippets.

@uzumaki-narut0
Created May 27, 2017 05:49
Show Gist options
  • Save uzumaki-narut0/cfd891265c66a62f2734076be924d2de to your computer and use it in GitHub Desktop.
Save uzumaki-narut0/cfd891265c66a62f2734076be924d2de to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
#define tr(c,it)\
for(typeof(c.begin()) = c.begin() ; it != c.end() ; it++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define present(c,x) (c.find(x) != c.end())
int main()
{
//code
int t;
cin>>t;
while(t--)
{
int n, i;
cin>>n;
vector<int> v1(n);
for(i=0 ; i<n ; i++)
{
cin>>v1[i];
}
i = 0;
int j = n-1;
int min_elem = INT_MAX;
pair<int, int> p1;
sort(all(v1));
for(; i<j ;)
{
if(v1[i] + v1[j] < 0)
{
if(abs(v1[i] + v1[j]) < min_elem)
{
min_elem = abs(v1[i] + v1[j]);
p1.first = v1[i];
p1.second = v1[j];
}
i++;
}
else
{
if(abs(v1[i] + v1[j]) < min_elem)
{
min_elem = abs(v1[i] + v1[j]);
p1.first = v1[i];
p1.second = v1[j];
}
j--;
}
}
cout<<p1.first<<" "<<p1.second<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment