Codeforces Round 867 (Div. 3) B - Karina and Array Solution
Problem Link : https://codeforces.com/contest/1822/problem/b
Solution in C++:
- /// Author : AH_Tonmoy
 - #include <bits/stdc++.h>
 - using namespace std;
 - int32_t main() {
 - ios_base::sync_with_stdio(0);
 - cin.tie(0);
 - int t;
 - cin >> t;
 - while (t--) {
 - long long n , ans = 0 ;
 - cin >> n ;
 - int cnt = 0 ;
 - std::vector<long long> a(n);
 - for ( int i = 0 ; i < n ; i++) {
 - cin >> a[i] ;
 - if ( a[i] < 0 ) cnt++;
 - }
 - sort(a.begin(),a.end()) ;
 - if ( cnt > 1 ) {
 - ans = max ( (a[0] * a[1]),(a[n-1] *a[n-2])) ;
 - cout << ans << endl;
 - }
 - else {
 - ans = a[n-1] * a[n-2] ;
 - cout << ans << endl;
 - }
 - }
 - }
 


No comments