fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void pVec(vector<int> f){
  5. for(auto i : f) cout << i << " ";
  6. cout << endl;
  7. }
  8. int main() {
  9. int t,n; cin >> t;
  10. while(t--){
  11. cin >> n;
  12.  
  13. vector<int> a(n),b(n);
  14. for(int i=0;i<n;i++) cin >> a[i];
  15. for(int i=0;i<n;i++) cin >> b[i];
  16.  
  17. int mxa = *max_element(a.begin(),a.end()), mxb = *max_element(b.begin(),b.end());
  18.  
  19. if(mxa >= mxb) for(int i=0;i<n;i++){ if(a[i] <= b[i]) swap(a[i],b[i]);}
  20. else for(int i=0;i<n;i++){ if(a[i] > b[i]) swap(a[i],b[i]);}
  21.  
  22. mxa = *max_element(a.begin(),a.end()), mxb = *max_element(b.begin(),b.end());
  23. cout << mxa * mxb << endl;
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5284KB
stdin
3
6
1 2 6 5 1 2
3 4 3 2 2 5
3
3 3 3
3 3 3
2
1 2
2 1
stdout
18
9
2