Break The Board Problem Statement

Your task is to break a board of given dimensions 'L' by 'W' into 'L' * 'W' smaller squares, ensuring the total cost of breaking is minimized.

Input:

The first line contains an integer 'T' indicating the number of test cases.
For each test case, the input is as follows:
- A line with two space-separated integers, 'L' and 'W', representing the length and width.
- A line with 'L' - 1 integers denoting the cost of each horizontal cut.
- A line with 'W' - 1 integers denoting the cost of each vertical cut.

Output:

For each test case, output an integer representing the minimum cost required to break the board into 'L' * 'W' squares.

Example:

Input:
1
4 3
2 1 3
1 2
Output:
10

Constraints:

  • 1 ≤ T ≤ 10
  • 2 ≤ L, W ≤ 104
  • 1 ≤ costL[i], costW[i] ≤ 105
  • Time Limit: 1 second

Note:

You are not required to print anything manually; implement the function to get the expected results.

Be the first one to answer
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

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