forked from 1laurelverma/DSA-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubArrayCodeChef.cpp
More file actions
47 lines (45 loc) · 1012 Bytes
/
Copy pathSubArrayCodeChef.cpp
File metadata and controls
47 lines (45 loc) · 1012 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
41
42
43
44
45
46
47
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
ll n;ll x;
cin>>n;
ll max=0;
ll min=0;
vector <ll> posi;
vector <ll> neg;
for(ll i =0;i<n;i++){
cin>>x;
if(x < 0){
neg.push_back(x);
}else{
posi.push_back(x);
}
}
sort(posi.begin(),posi.end());
sort(neg.begin(),neg.end());
if(neg.empty()){
max = posi.back()*posi.back();
min = posi.front()*posi.front();
}else if(posi.empty()){
max = neg.front()*neg.front();
min = neg.back()*neg.back();
}
else{
if(neg.front()*neg.front()< posi.back()*posi.back()){
max = posi.back()*posi.back();
}
else{
max = neg.front()*neg.front();
}
min = neg.front() * posi.back();
}
cout<<min<<" "<<max<<endl;
}
return 0;
}