can anyone tell me what is wrong with my code? I thought that it was pretty simple. Just take the intersection between W and B1 then W and B2. If they add up to a sum greater than the area of W, then return “NO” else “YES”.
#include <bits/stdc++.h>
using namespace std;
struct Rect {
long x1;
long y1;
long x2;
long y2;
int find_area() {
return abs(x2 - x1) * abs(y2 - y1);
}
};
int intersection_area(Rect a, Rect b) {
long bound = 0;
return (max(bound, (min(a.x2, b.x2) - max(a.x1, b.x1)) * (min(a.y2, b.y2) - max(a.y1, b.y1))));
}
int main() {
Rect w;
Rect b1;
Rect b2;
cin >> w.x1 >> w.y1 >> w.x2 >> w.y2;
cin >> b1.x1 >> b1.y1 >> b1.x2 >> b1.y2;
cin >> b2.x1 >> b2.y1 >> b2.x2 >> b2.y2;
if(w.find_area() > intersection_area(w, b1) + intersection_area(w, b2)) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}