// C++ code to implement the approach
#include <bits/stdc++.h>
using namespace std;
// Function to find maximum and minimum
// number of co-ordinates in given
// rectangle after making cuts
void findMinMax(int W, int H, int cor[][2], int N,
vector<int>& A, vector<int>& B, int X,
int Y)
{
// Creating hashmap
map<pair<pair<int, int>, pair<int, int> >, int> HashMap;
// creating edges of rectangle
vector<int> arr1(X + 2, 0), arr2(Y + 2, 0);
// copying array A to arr1
for (int i = 1; i <= X; i++)
arr1[i] = A[i - 1];
arr1.back() = W;
// copying array B to arr2
for (int i = 1; i <= Y; i++)
arr2[i] = B[i - 1];
arr2.back() = H;
// iterating each co-ordinate
for (int i = 0; i < N; i++) {
// locating x co-ordinate
int ind1 = lower_bound(arr1.begin(), arr1.end(),
cor[i][0])
- arr1.begin();
// locating y co-ordinate
int ind2 = lower_bound(arr2.begin(), arr2.end(),
cor[i][1])
- arr2.begin();
// increasing counter of HashMap
HashMap[{ { arr1[ind1 - 1], arr1[ind1] },
{ arr2[ind2 - 1], arr2[ind2] } }]++;
}
// max and min answer
int minAns = INT_MAX, maxAns = INT_MIN;
// iterating the HashMap
for (auto e : HashMap) {
minAns = min(e.second, minAns);
maxAns = max(e.second, maxAns);
}
// if HashMap has all rectangles
if (HashMap.size() == ((X + 1) * (Y + 1))) {
// printing minAns and maxAns
cout << minAns << " " << maxAns << endl;
}
else {
// printing the minimum answer and maximum answer
cout << 0 << " " << maxAns << endl;
}
}
// Driver Code
int32_t main()
{
// Input 1
int W = 7, H = 6;
int cor[][2] = { { 6, 1 },
{ 3, 1 },
{ 4, 2 },
{ 1, 5 },
{ 6, 2 } },
N = 5;
vector<int> A = { 2, 5 };
vector<int> B = { 3, 4 };
int X = 2, Y = 2;
// Function Call
findMinMax(W, H, cor, N, A, B, X, Y);
// Input 2
int W1 = 4, H1 = 4;
int cor1[][2]
= { { 1, 1 }, { 3, 1 }, { 3, 3 }, { 1, 3 } },
N1 = 4;
vector<int> A1 = { 2 };
vector<int> B1 = { 2 };
int X1 = 1, Y1 = 1;
// Function Call
findMinMax(W1, H1, cor1, N1, A1, B1, X1, Y1);
return 0;
}