BITMASK2 - Editorial

Problem Link:

Practice
Contest

Difficulty:

Easy

Problem:

Given two vectors, we have to arrange the elements of these vectors in such a way that their dot product is minimum.

Quick Explanation:

We need to sort one vector in ascending order and other in descending order to get the minimum dot product.

Explanation

Dot product of two vectors [a1,a2,a3,…,an] and [b1,b2,b3,…,bn] is given by a1*b1 + a2*b2 + a3*b3 + ... +an*bn. To minimise the dot product of two vectors we need to multiply the largest of one vector with the smallest of second vector and so on. Thus we need to sort both vectors one in ascending and other in descending. And perform the dot product.

Solution:

Authors solution can be found here

//