Codey and Zombies
https://www.hackerrank.com/contests/codenection-2023-final-round-open-category/challenges/cn-c14
Last updated
https://www.hackerrank.com/contests/codenection-2023-final-round-open-category/challenges/cn-c14
Last updated
Codey is on its way back home, as usual. To get there, it has to traverse a field that can be represented as an n * m
grid. However, today is different because the field is inhabited by zombies! Codey is aware that the only way to eliminate the zombies is by setting them on fire.
So, Codey has devised an ingenious plan for this task, involving the use of bombs. Codey can place a bomb at a cell , and doing so requires a total of units of fire powder. Codey is allowed to place at most one bomb on each cell . When Codey detonates a bomb in cell , it results in the burning of every cell in row i
and every cell in column j
. This means that all zombies in the corresponding rows and columns will be killed when Codey detonates the bombs.
What are the minimum and maximum amounts of fire powder Codey could use to guarantee the elimination of every zombie?
The first line contains n
and m
, where n
represents the number of rows and m
represents the columns in the 2D grid.
The second line contains n
integers, , each representing the values fire powder for each row.
The third line contains m
integers, , each representing the values fire powder for each row.
Output two integers, maximum and minimum amount of firepower Codey can use.
The picture below shows the position of the bombs that can ensure the minimum amount of fire powder used .
And this is the maximum amount of fire power Codey can use to eliminate all the zombies which is .
This is because,
Find the minimum value from that longest array,
Multiply it with length of shortest array, and add the elements on shortest array
The easiest part should be adding all the numbers in rows/column, then multiply with length of rows/columns, .