# Maximum given sized rectangles that can be cut out of a sheet of paper

Given the length L and breadth B of a sheet of paper, the task is to find the maximum number of rectangles with given length l and breadth b that can be cut from this sheet of paper.

Examples:

Input: L = 5, B = 2, l = 14, b = 3
Output: 0
The sheet is smaller than the required rectangle. So, no rectangle of the given dimension can be cut from the sheet.

Input: L = 10, B = 7, l = 4, b = 3
Output: 4

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

• Try to cut the rectangles horizontally i.e. length of the rectangle is aligned with the length of the sheet and breadth of the rectangle is aligned with the breadth of the sheet and store the count of rectangles possible in horizontal.
• Repeat the same with vertical alignment i.e. when length of the rectangle is aligned with the breadth of the sheet and breadth of the rectangle is aligned with the length of the sheet and store the result in vertical. Print max(horizontal, vertical) as the result.

Below is the implementation of the above approach:

## C++

 `// CPP implementation of the approach ` `#include ` `using` `namespace` `std; ` ` `  `// Function to return the maximum rectangles possible ` `int` `maxRectangles(``int` `L, ``int` `B, ``int` `l, ``int` `b) ` `{ ` `    ``int` `horizontal = 0, vertical = 0; ` ` `  `    ``// Cut rectangles horizontally if possible ` `    ``if` `(l <= L && b <= B)  ` `    ``{ ` ` `  `        ``// One rectangle is a single cell ` `        ``int` `columns = B / b; ` `        ``int` `rows = L / l; ` ` `  `        ``// Total rectangles = total cells ` `        ``horizontal = rows * columns; ` `    ``} ` ` `  `    ``// Cut rectangles vertically if possible ` `    ``if` `(l <= B && b <= L) ` `    ``{ ` `        ``int` `columns = L / b; ` `        ``int` `rows = B / l; ` ` `  `        ``vertical = rows * columns; ` `    ``} ` ` `  `    ``// Return the maximum possible rectangles ` `    ``return` `max(horizontal, vertical); ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `L = 10, B = 7, l = 4, b = 3; ` `    ``cout << (maxRectangles(L, B, l, b)) << endl; ` `} ` ` `  `// This code is contributed by ` `// Sanjit_Prasad `

## Java

 `// Java implementation of the approach ` `class` `GFG { ` ` `  `    ``// Function to return the maximum rectangles possible ` `    ``static` `int` `maxRectangles(``int` `L, ``int` `B, ``int` `l, ``int` `b) ` `    ``{ ` `        ``int` `horizontal = ``0``, vertical = ``0``; ` ` `  `        ``// Cut rectangles horizontally if possible ` `        ``if` `(l <= L && b <= B) { ` ` `  `            ``// One rectangle is a single cell ` `            ``int` `columns = B / b; ` `            ``int` `rows = L / l; ` ` `  `            ``// Total rectangles = total cells ` `            ``horizontal = rows * columns; ` `        ``} ` ` `  `        ``// Cut rectangles vertically if possible ` `        ``if` `(l <= B && b <= L) { ` `            ``int` `columns = L / b; ` `            ``int` `rows = B / l; ` ` `  `            ``vertical = rows * columns; ` `        ``} ` ` `  `        ``// Return the maximum possible rectangles ` `        ``return` `Math.max(horizontal, vertical); ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``int` `L = ``10``, B = ``7``, l = ``4``, b = ``3``; ` `        ``System.out.print(maxRectangles(L, B, l, b)); ` `    ``} ` `} `

## Python3

 `# Python3 implementation of the approach  ` ` `  `# Function to return the maximum  ` `# rectangles possible  ` `def` `maxRectangles(L, B, l, b):  ` ` `  `    ``horizontal, vertical ``=` `0``, ``0` ` `  `    ``# Cut rectangles horizontally if possible  ` `    ``if` `l <``=` `L ``and` `b <``=` `B: ` ` `  `        ``# One rectangle is a single cell  ` `        ``columns ``=` `B ``/``/` `b  ` `        ``rows ``=` `L ``/``/` `l  ` ` `  `        ``# Total rectangles = total cells  ` `        ``horizontal ``=` `rows ``*` `columns  ` ` `  `    ``# Cut rectangles vertically if possible  ` `    ``if` `l <``=` `B ``and` `b <``=` `L: ` `     `  `        ``columns ``=` `L ``/``/` `b  ` `        ``rows ``=` `B ``/``/` `l  ` ` `  `        ``vertical ``=` `rows ``*` `columns  ` ` `  `    ``# Return the maximum possible rectangles  ` `    ``return` `max``(horizontal, vertical)  ` ` `  `# Driver code  ` `if` `__name__ ``=``=` `"__main__"``: ` ` `  `    ``L, B, l, b ``=` `10``, ``7``, ``4``, ``3` `    ``print``(maxRectangles(L, B, l, b))  ` ` `  `# This code is contributed by Rituraj Jain `

## C#

 `// C# implementation of the above approach  ` `using` `System; ` ` `  `class` `GFG  ` `{  ` ` `  `    ``// Function to return the  ` `    ``// maximum rectangles possible  ` `    ``static` `int` `maxRectangles(``int` `L, ``int` `B,  ` `                                ``int` `l, ``int` `b)  ` `    ``{  ` `        ``int` `horizontal = 0, vertical = 0;  ` ` `  `        ``// Cut rectangles horizontally if possible  ` `        ``if` `(l <= L && b <= B) ` `        ``{  ` ` `  `            ``// One rectangle is a single cell  ` `            ``int` `columns = B / b;  ` `            ``int` `rows = L / l;  ` ` `  `            ``// Total rectangles = total cells  ` `            ``horizontal = rows * columns;  ` `        ``}  ` ` `  `        ``// Cut rectangles vertically if possible  ` `        ``if` `(l <= B && b <= L)  ` `        ``{  ` `            ``int` `columns = L / b;  ` `            ``int` `rows = B / l;  ` `            ``vertical = rows * columns;  ` `        ``}  ` ` `  `        ``// Return the maximum possible rectangles  ` `        ``return` `Math.Max(horizontal, vertical);  ` `    ``}  ` ` `  `    ``// Driver code  ` `    ``public` `static` `void` `Main()  ` `    ``{  ` `        ``int` `L = 10, B = 7, l = 4, b = 3;  ` `        ``Console.WriteLine(maxRectangles(L, B, l, b));  ` `    ``}  ` `}  ` ` `  `// This code is contributed by Ryuga `

## PHP

 ` `

Output:

```4
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.