Block Game

0

0 votes
Medium
Problem

Chotu is playing a game. He is having N stacks having a1, a2, a3...an wooden blocks respectively, each block has unit height. His objective is to make every stack equal in height. This can be done by removing blocks from a stack or adding some blocks to a stack. Removing a block or adding a block is done at certain cost for each stack which will be given along with the no. of blocks of the stack. Find the minimal cost at which Chotu can complete the game i.e make every stack equal in height.
All blocks are of same dimension.

Input
The first line contains an integer T denoting the number of test cases followed by 3T lines.
The first line of each test case contains an integer N as described above.
The second line contains N integers a1, a2, a3...an where ai denotes the number of blocks in ith stack.
The third line contains N integers c1, c2, c3...cn where ci denotes the cost of adding or removing a block to ith stack.

Constraints
1 <= T <= 20
1 <= N <= 104
1 <= ai , ci <= 104

Sample Input
1
3
1 2 3
10 100 1000
Sample Output
120
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?