Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 786 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

You are given two arrays,** A** and **B**, of equal size **N**. The task is to find the minimum value of A[0] * B[0] + A[1] * B[1] +…+ A[N-1] * B[N-1], where shuffling of elements of arrays A and B is allowed.

**Input:**

The first line of input contains an integer **T** denoting the no of test cases. Then** T** test cases follow. Each test case contains three lines. The first line contains an integer **N** denoting the size of the arrays. In the second line are N space separated values of the array **A[]**, and in the last line are N space separated values of the array **B[]**.

**Output:**

For each test case, print the minimum sum.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{7}

1 <= A[] <= 10^{18}

**Example:
Input:**

2

3

3 1 1

6 5 4

5

6 1 9 5 4

3 4 8 2 4

23

80

**Explanation:**

**For testcase1**: 1*6+1*5+3*4 = 6+5+12 = 23 is the minimum sum

**For testcase2**: 2*9+3*6+4*5+4*4+8*1 =18+18+20+16+8 = 80 is the minimum sum

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Minimize the sum of product

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.