Page 1 of 1

Must be written in Javascript. [Problem Description] Residents of the imaginary island "ZERO" with many tall buildings d

Posted: Fri Jul 08, 2022 6:40 am
by answerhappygod
Must be written in Javascript.[Problem Description]
Residents of the imaginary island "ZERO" with many tallbuildings decided to demolish all the buildings, butSince it costs more money than expected, we are going to remodelthe existing building and change it to an extension or remodelingmethod.
Increasing the height of a building by 1 does not costdemolition and costs 1 per heightAlso, if the height of a building is reduced by 1, the cost ofdemolishing + rebuildingConsumes 1 per height.
Buildings are never the same height because they allhave to be built.
Our goal is to estimate how much it will cost to extendor demolish any building to the desired height.
For example, if the current height now = [1, 2, 3, 4, 5]and the target height tobe = [6, 5, 4, 2, 0] , then
When 1 -> 6, it costs 5
When 2 -> 5, it costs 3
When 3 -> 4, the cost is equal to 1,
When 4 -> 2, it costs 4 +2,
When it becomes 5 -> 0, it costs 5 +0, resulting in acost of 20.
[Restrictions]
- The maximum value of the building height is 10000.
- There is more than one building on the "ZERO" island.
- There are no negative numbers in now and tobe.
- The height of the original building cannot be the same as theheight after extension or remodeling.
[Input format]
- You are given an array of "now" and an array of "tobe".
[Output Format]
- When all buildings are extended or remodeled to the desiredheight, the cost is refunded.
//
function solution(now, tobe) {
var answer = 0;
return answer;
}
//