Maximum of smallest possible area that can get with exactly k cut of given rectangular
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.
Examples :
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
C++
#include <bits/stdc++.h> using namespace std; void max_area(int n, int m, int k) { if (k > (n + m - 2)) cout << "Not possible" << endl; else { int result; // for the 1st case if (k < max(m, n) - 1) { result = max(m * (n / (k + 1)), n * (m / (k + 1))); } // for the second case else { result = max(m / (k - n + 2), n / (k - m + 2)); } // print final result cout << result << endl; } } // driver code int main() { int n = 3, m = 4, k = 1; max_area(n, m, k); } |
Java
// Java code for Maximum of smallest // possible area that can get with // exactly k cut of given rectangular class GFG { //Utility Function static void max_area(int n, int m, int k) { if (k > (n + m - 2)) System.out.println("Not possible"); else { int result; // for the 1st case if (k < Math.max(m, n) - 1) { result = Math.max(m * (n / (k + 1)), n * (m / (k + 1))); } // for the second case else { result = Math.max(m / (k - n + 2), n / (k - m + 2)); } // print final result System.out.println(result); } } // Driver code public static void main (String[] args) { int n = 3, m = 4, k = 1; max_area(n, m, k); } } // This code is contributed by Anant Agarwal. |
Python3
# Python3 code for Maximum of smallest # possible area that can get with # exactly k cut of given rectangular def max_area(n,m,k): if (k > (n + m - 2)): print("Not possible") else: # for the 1st case if (k < max(m,n) - 1): result = max(m * (n / (k + 1)), n * (m / (k + 1))); # for the second case else: result = max(m / (k - n + 2), n / (k - m + 2)); # print final result print(result) # driver code n = 3m = 4k = 1 max_area(n, m, k) # This code is contributed # by Azkia Anam. |
C#
// C# code for Maximum of smallest // possible area that can get with // exactly k cut of given rectangular using System; class GFG { //Utility Function static void max_area(int n, int m, int k) { if (k > (n + m - 2)) Console.WriteLine("Not possible"); else { int result; // for the 1st case if (k < Math.Max(m, n) - 1) { result = Math.Max(m * (n / (k + 1)), n * (m / (k + 1))); } // for the second case else { result = Math.Max(m / (k - n + 2), n / (k - m + 2)); } // print final result Console.WriteLine(result); } } // Driver code public static void Main () { int n = 3, m = 4, k = 1; max_area(n, m, k); } } // This code is contributed by vt_m. |
PHP
<?php // PHP code for Maximum of smallest // possible area that can get with // exactly k cut of given rectangular function max_area($n, $m, $k) { if ($k > ($n + $m - 2)) echo "Not possible" ,"\n"; else { $result; // for the 1st case if ($k < max($m, $n) - 1) { $result = max($m * ($n / ($k + 1)), $n * ($m / ($k + 1))); } // for the second case else { $result = max($m / ($k - $n + 2), $n / ($k - $m + 2)); } // print final result echo $result ,"\n"; } } // Driver Code $n = 3; $m = 4; $k = 1; max_area($n, $m, $k); // This code is contributed by ajit ?> |
Output :
6
Recommended Posts:
- Maximum area of quadrilateral
- Maximum area of rectangle possible with given perimeter
- Rectangle with Maximum Area using Java Pair
- Maximum area of triangle having different vertex colors
- Number of squares of maximum area in a rectangle
- Find maximum volume of a cuboid from the given perimeter and area
- Maximum area rectangle by picking four sides from array
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- Rectangular (or Pronic) Numbers
- Sum of lengths of all 12 edges of any rectangular parallelepiped
- Find the volume of rectangular right wedge
- 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
- Minimum number of square tiles required to fill the rectangular floor
- Area of a Hexagon
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.



