Hi , can anyone please suggest where I am going wrong in this solution:
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
void printBox(long long box[])
{
cout<<"[ ";
for(long long i=0;i<4;i++)
cout<<box[i]<<" ";
cout<<"]\n";
}
bool inquad(long long quad[],pair<long long,long long> point)
{
long long x = point.first;
long long y = point.second;
//printBox(quad);
//cout<<x<<","<<y<<"\n";
if(x>=quad[0] and y>=quad[2] and x<=quad[1] and y<=quad[3])
{
return true;
}
return false;
}
long long area(long long box[])
{
return (box[1]-box[0])*(box[3]-box[2]);
}
long long join(long long box1[],long long box2[])
{
long long f1=box1[0];
long long f2=box2[0];
if(f1 ==-1 and f2 == -1)
return 0;
if(f1 == -1)
return area(box2);
if(f2 == -1)
return area(box1);
long long b[4];
b[0] = min(box1[0],box2[0]);
b[1] = max(box1[1],box2[1]);
b[2] = min(box1[2],box2[2]);
b[3] = max(box1[3],box2[3]);
return area(b);
}
void updateBox(long long (&box)[4],pair<long long,long long> point)
{
long long x = point.first;
long long y = point.second;
if(box[0] == -1 or box[0]>x)
box[0] = x;
if(box[1] == -1 or box[1]<x)
box[1] = x;
if(box[2] == -1 or box[2]>y)
box[2] = y;
if(box[3] == -1 or box[3]<y)
box[3] = y;
}
pair<long long,long long> points[100002];
int main()
{
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
long long T;
cin>>T;
while (T--)
{
long long N;
cin>>N;
//vector<pair<long long,long long>> points;
long long left = -1, right = -1, top = -1, bottom = -1;
for(long long i=0;i<N;i++)
{
long long x,y;
cin>>x>>y;
points[i] = make_pair(x,y);
if(left == -1 || left>x)
{
left = x;
}
if(right == -1 || right<x)
{
right = x;
}
if(top == -1 || top>y)
{
top = y;
}
if(bottom == -1 || bottom<y)
{
bottom = y;
}
}
long long midx = (left+right)/2;
long long midy = (top+bottom)/2;
long long Q[4][4];
// cout<<left<<" "<<right<<" "<<top<<" "<<bottom<<"\n";
Q[0][0] = left;
Q[0][1] = midx;
Q[0][2] = top;
Q[0][3] = midy;
Q[1][0] = midx;
Q[1][1] = right;
Q[1][2] = top;
Q[1][3] = midy;
Q[2][0] = left;
Q[2][1] = midx;
Q[2][2] = midy;
Q[2][3] = bottom;
Q[3][0] = midx;
Q[3][1] = right;
Q[3][2] = midy;
Q[3][3] = bottom;
long long box[4][4];
for(long long i=0;i<4;i++)
for(long long j=0;j<4;j++)
box[i][j]=-1;
for(long long i=0;i<N;i++)
{
for(long long j=0;j<4;j++)
{
if(inquad(Q[j],points[i]))
{
updateBox(box[j],points[i]);
break;
}
}
}
long long a1 = join(box[0],box[1])+join(box[2],box[3]);
long long a2 = join(box[0],box[2])+join(box[1],box[3]);
cout<<min(a1,a2)<<"\n";
}
}