Bunny, the Jumper

5

2 votes
Dynamic Programming, Algorithms, Applications of Dynamic Programming
Problem

You're in an imaginary city where Bugs Bunny, the rabbit lives. Bugs needs to navigate through a row of N cells in the city, where each cell can either be a rabbit hole (Bugs can enter it) or an obstacle that he can't jump into.

Your mission is to guide Bugs through the city successfully. Bugs starts by hopping into the xth cell from the beginning, then jumps to x+yth cell, then jumps to x+2yth cell and so on until he reaches a cell beyond the last one. If any of these cells is an obstacle, Bugs can't proceed.

To help Bugs on his adventure, you can modify the city layout with two actions:

  • Spend A[i] coins to turn an obstacle cell into a rabbit hole
  • Spend B coins to remove the first cell entirely and thus changing the number of cells, but you must maintain a minimum of x cells in the city.

Your challenge is to calculate the minimum cost in coins required to modify the city layout, ensuring that Bugs Bunny can follow the given x and y pattern.

Input Format:

  •  First line of the input contains an integer T, representing the number of test cases.
  • The first line of each test case contains an integer N representing the number of cells in the city.
  • The next line of each test case contains 3 integers xy and B as given in the question.
  • The next line of each test case contains N integers separated by space containting either 0 or 1, indicating if ith city contains an obstacle or a rabbit hole respectively.
  • The next line of each test case contains N integers separated by space representing the array A.

Output Format:

  • For each test case, output a single integer representing the minimum coins required.

Constraints

  • 1T105
  • 1N105
  • 1A[i],B109
  • 1x,yN
  • It is guaranteed that sum of N over all test cases does not exceed 106
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • Test Case 1: We can remove the obstacle on the 3rd cell, incurring a cost of 3 coins.
  • Test Case 2: To solve this case, we remove the first 3 cells from the city, incurring a total cost of 9 coins.
  • Test Case 3: We can remove the obstacle on the 4th cell and then remove the first cell from the city, incurring a cost of 4 coins.
  • Test Case 4: In the last test case, we don't need to make any modifications, so the minimum cost remains 0 coins.
Editor Image

?