Deep Loves Function Minimization

4.3

6 votes
Sorting, Algorithms, Advanced Sorting
Problem

Given a  3N matrix. In one operation you can swap any two-column and you can perform this operation any number of times (including zero). Find the minimum possible value of the given function after performing this operation any number of times (including zero). As this value may become very large, so output the answer modulo 109+7. The function is given below:

                                                      

Input Format:

  • The first line contains T denoting the number of test cases. The description of each test case is as follows.
  • First-line contains an integer N, denoting the number of columns of the matrix.
  • It follows with 3 line each contains N integers.

Output Format:

  • For each test case, print a single line containing one integer — the minimum value F modulo 109+7.

Constraints:

  • 1T15
  • 2N105
  • 1A1,i,A2,i,A3,i104
Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

We can swap 1'st and 2'nd column and the answer will be 2 * (1 * 20 + 2 * 2) + 1 * (2 * 2) = 52 and this the minimum possible answer.

Editor Image

?