Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@mantu_singh | 3530 |

@marius_valentin_dragoi | 3523 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1160 |

@gurshehzadsingh | 847 |

@nithinreddy3210 | 739 |

@mohanreddy8847 | 702 |

@AkashLahoty | 606 |

@jha8768 | 583 |

@workit | 582 |

@balwanyadav34 | 582 |

@pritsahkar2000 | 580 |

@dipeshtiwari47 | 575 |

@divyagupta221100 | 557 |

Complete Leaderboard |

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
adding one in 1" or "Adding two blocks in
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

**Your Task:**

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 ≤ 10^{6}

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?

YesLoading...

Equalize the Towers

...