Codeforces Round 867 (Div. 3) B - Karina and Array Solution


 

Problem Link : https://codeforces.com/contest/1822/problem/b

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. long long n , ans = 0 ;
  11. cin >> n ;
  12. int cnt = 0 ;
  13. std::vector<long long> a(n);
  14. for ( int i = 0 ; i < n ; i++) {
  15. cin >> a[i] ;
  16. if ( a[i] < 0 ) cnt++;
  17. }
  18. sort(a.begin(),a.end()) ;
  19. if ( cnt > 1 ) {
  20. ans = max ( (a[0] * a[1]),(a[n-1] *a[n-2])) ;
  21. cout << ans << endl;
  22. }
  23. else {
  24. ans = a[n-1] * a[n-2] ;
  25. cout << ans << endl;
  26. }
  27. }
  28. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.