Saturday, June 16, 2018

FASHION - Fashion Shows : Classical

#The solution in Python 3 is as follows:

t=int(input())
i=0
while i<t:
    s=0
    n=int(input())
    a=list(map(int, input().split()))       #store the inputs in a list
    b=list(map(int, input().split()))
    a.sort()                                           #sort the lists in ascending order
    b.sort()
    j=0
    while j<n:
        s+=a[j]*b[j]                                #required calculation
        j+=1
    print(s)
    i+=1


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!