click below for solution

Thursday, 27 January 2022

Min Max Swap Solution|Codeforces Round #768 (div 2)

                                                 A. Min Max Swap

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two arrays a and b of n positive integers each. You can apply the following operation to them any number of times:

  • Select an index i (1in) and swap ai with bi (i. e. ai becomes bi and vice versa).

Find the minimum possible value of max(a1,a2,,an)max(b1,b2,,bn) you can get after applying such operation any number of times (possibly zero).

Input

The input consists of multiple test cases. The first line contains a single integer t (1t100) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer n (1n100) — the length of the arrays.

The second line of each test case contains n integers a1,a2,,an (1ai10000) where ai is the i-th element of the array a.

The third line of each test case contains n integers b1,b2,,bn (1bi10000) where bi is the i-th element of the array b.

Output

For each test case, print a single integer, the minimum possible value of max(a1,a2,,an)max(b1,b2,,bn) you can get after applying such operation any number of times.

Note

In the first test, you can apply the operations at indices 2 and 6, then a=[1,4,6,5,1,5] and b=[3,2,3,2,2,2]max(1,4,6,5,1,5)max(3,2,3,2,2,2)=63=18.

In the second test, no matter how you apply the operations, a=[3,3,3] and b=[3,3,3] will always hold, so the answer is max(3,3,3)max(3,3,3)=33=9.

In the third test, you can apply the operation at index 1, then a=[2,2]b=[1,1], so the answer is max(2,2)max(1,1)=21=2.

Solution:

This question solution is updated within contest time. please click on follow button and subscribe our channel.if you follow then get notification of answer as soon as possible.


1 comment:

  1. #include
    using namespace std;

    int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
    int n;
    cin>>n;
    int max=-1;
    int min=-1;
    int a[n];
    for(int i=0; i>y;
    a[i]=y;
    }
    int b[n];
    for(int j=0; j>y;
    b[j]=y;
    }

    for(int k=0;k<n;k++){
    if(a[k]<b[k]){
    int x=a[k];
    a[k]=b[k];
    b[k]=x;
    }
    }
    cout<<(*max_element(a,a+n))*(*max_element(b,b+n))<<endl;


    }
    }

    ReplyDelete