#P12218. Minimize Total Toy Weight
Minimize Total Toy Weight
Minimize Total Toy Weight
You are given 2n parts with weights \(w_1, w_2, \dots, w_{2n}\). You need to pair them up into n toys. The weight of a toy formed by two parts is defined as the product of their weights. Formally, if you pair parts with weights \(a\) and \(b\) then the toy's weight is \(a \times b\).
Your task is to determine the minimum possible total weight of all the toys, that is, minimize the sum:
[ \sum_{i=1}^{n} (a_i \times b_i), ]
where each part is used exactly once.
inputFormat
The first line contains an integer n (the number of toys). The second line contains 2n integers \(w_1, w_2, \dots, w_{2n}\) separated by spaces, representing the weights of the parts.
outputFormat
Output a single integer representing the minimum total weight achievable by optimally pairing the parts to form n toys.
sample
1
3 4
12