Break The Board

You’re given a board of length 'L' and width 'W'. Your task is to break this board into 'L' * 'W' smaller squares, such that the total cost involved in breaking is the minimum possible.

NOTE:
The breaking cost of each edge for the board will be given.
Input Format:
The first line of input contains 'T', the number of test cases.
The first line of each test case contains two space-separated integers 'L' and 'W', denoting the length and width of the box. 
The second line contains 'L' - 1 space-separated integer, where the 'ith' integer denotes the cost of one horizontal cut between the rows 'i' and 'i' + 1.
The third line contains 'W' - 1 space-separated integer, where the 'ith' integer denotes the cost of one vertical cut between the columns 'i' and 'i' + 1.
Output Format:
The only line of output of each test case should contain an integer denoting the minimum cost required to break the board into 'L' * 'W' squares.
Note:
You don’t need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
2 <= L, W <= 10 ^ 4
1 <= costL[i], costW[i] <= 10 ^ 5

Time Limit: 1 sec
CodingNinjas
author
2y
Greedy Approach

This problem can be solved using the greedy approach. By greedy, we mean that we simply start cutting the board along every horizontal and vertical line. But this cutting needs to be i...read more

Help your peers!
Add answer anonymously...
Twitter Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter