KOPC12A - K12 - Building Construction
Given N buildings of height h1,h2,h3...hn, the objective is to make every building has equal height. This can be done by removing bricks from a building or adding some bricks to a building.Removing a brick or adding a brick is done at certain cost which will be given along with the heights of the buildings.Find the minimal cost at which you can make the buildings look beautiful by re-constructing the buildings such that the N buildings satisfy
h1=h2=h3=..=hn=k ( k can be any number).
For convenience, all buildings are considered to be vertical piles of bricks, which are of same dimensions.
The first line of input contains an integer T which denotes number of test cases .This will be followed by 3*T lines , 3 lines per test case. The first line of each test case contains an integer n and the second line contains n integers which denotes the heights of the buildings [h1,h2,h3....hn] and the third line contains n integers [c1,c2,c3...cn] which denotes the cost of adding or removing one unit of brick from the corresponding building.
The output must contain T lines each line corresponding to a testcase.
1 3 1 2 3 10 100 1000 Output:
i thnk we have to add a brick from outside.i mean ,brick need not be from other building.Ex-add a brick to 2 and two bricks to 1.Total cost = 120
K=3 All n buildings must be the same height. Height of zero doesn't decrease n. removing from one building is an action on that building. Adding it to another is another action on the other building. 10 to add a brick to the frst building twice is 20. 100 to add a brick to second building is 120.
Wait, I think I understand. Does the sum of all heights has to be the same at the end? If the answer is NO then I understand everything now...
I just do not understand the test case. Why is the solution 120?