Given n×m big rectangular area with unit squares and k times cut is allowed, the cut should be straight (horizontal or vertical) and should go along the edges of the unit square. What is the maximum possible area of the smallest piece he can get with exactly k cuts.
Input : 3 4 1 Output : 6 Input : 6 4 2 Output : 8
Image for 2nd input
Image for 1st input
As this is n×m rectangular area so there are (n-1) rows and (m-1) columns . So if k > (n + m – 2) then, then cut are not possible . Then, if k is less than that . There will be two cases
- When k is less than max( n, m ) – 1 : In the 1st case, if k is less than max( n, m ) – 1, then either m * ( n / ( k+1 ) ) or n * ( m / ( k+1 ) ) is maximum, here we have divided by ( k + 1) because horizontally or vertically i.e ( m * n = total blocks ) is divided into ( k + 1 ) parts.
- When k is greater than or equal to max( n, m) – 1 : In the 2nd case, if k >= max( n, m ) – 1, then there will be cut on both rows as well as columns so, the maximum possible smallest area will be either m / ( k – n + 2) or n / ( k – m + 2 ) . In this case suppose if n > m then, firstly n-1 (row or column) cut is possible . After that (k – n) cut will be done on m – 1 . So, here we have adjusted this ( k – n ) cut such that smallest possible division should be maximum.
Code – Below is the implementation of the following approach
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Maximum area of quadrilateral
- Maximum area of rectangle possible with given perimeter
- Number of squares of maximum area in a rectangle
- Rectangle with Maximum Area using Java Pair
- Maximum area of triangle having different vertex colors
- Maximum area rectangle by picking four sides from array
- Maximum area of rectangle inscribed in an equilateral triangle
- Find maximum volume of a cuboid from the given perimeter and area
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- Rectangular (or Pronic) Numbers
- Calculate Volume, Curved Surface Area and Total Surface Area Of Cylinder
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Identical Splitting in a rectangular grid
- Height of Pyramid formed with given Rectangular Box
- Find the volume of rectangular right wedge
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.