Time limit
Memory limit
You are given two integer arrays A and B, each of length N. Define the function S as follows.
$$S = A_0 \times B_0 + A_1 \times B_1 + \cdots + A_{N-1} \times B_{N-1}$$
You may freely rearrange the elements of A, but the elements of B must keep their given order. Write a program that finds the minimum possible value of S.
The first line contains the array length N. The second line contains the N elements of array A in order, and the third line contains the N elements of array B in order.
N is a natural number not greater than 50, and every element of A and B is a non-negative integer not greater than 100.
Print the minimum value of S on the first line.
To make S as small as possible, pair the largest values of A with the smallest values of B.