Maximum of smallest possible area that can get with exactly k cut of given rectangular in C++


In this tutorial, we will be discussing a program to find the maximum of smallest possible area that can get with exactly k cut of given rectangular.

For this we will be provided with the sides of the rectangle and the number of cuts that can be made. Our task is to calculate the smallest area that can be achieved by making the given number of cuts.

Example

 Live Demo

#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;
      if (k < max(m, n) - 1) {
         result = max(m * (n / (k + 1)), n * (m / (k + 1)));
      }
      else {
         result = max(m / (k - n + 2), n / (k - m + 2));
      }
      cout << result << endl;
   }
}
int main() {
   int n = 3, m = 4, k = 1;
   max_area(n, m, k);
   return 0;
}

Output

6

Updated on: 09-Sep-2020

75 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements