Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@mantu_singh 3530
@marius_valentin_dragoi 3523
@sushant_a 3459
Equalize the Towers
Easy Accuracy: 50.83% Submissions: 262 Points: 2

Given heights h[] of N towers, the task is to bring every tower to the same height by either adding or removing blocks in a tower. Every addition or removal operation costs cost[] a particular value for the respective tower. Find out the Minimum cost to Equalize the Towers.

Example 1:

Input: N = 3, h[] = {1, 2, 3}
cost[] = {10, 100, 1000}
Output: 120
Explanation: The heights can be equalized
by either "Removing one block from 3 and
1 and adding one in 2". Since the cost
of operation in tower 3 is 1000, the first
process would yield 1010 while the second
one yields 120. Since the second process
yields the lowest cost of operation, it is
the required output.

Example 2:

Input: N = 5, h[] = {9, 12, 18, 3, 10}
cost[] = {100, 110, 150, 25, 99}
Output: 1623


This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function Bsearch() that takes integer N, array H, and array Cost as parameters and returns the minimum cost required to equalize the towers.

Expected Time Complexity: O(NlogN).
Expected Auxiliary Space: O(1).

Constraints:
1 ≤ N ≤ 106