Algorithm


C. White Sheet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0)(0,0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1)(�1,�1), and the top right — (x2,y2)(�2,�2).

After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x3,y3)(�3,�3), and the top right — (x4,y4)(�4,�4). Coordinates of the bottom left corner of the second black sheet are (x5,y5)(�5,�5), and the top right — (x6,y6)(�6,�6).

Example of three rectangles.

Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.

Input

The first line of the input contains four integers x1,y1,x2,y2�1,�1,�2,�2 (0x1<x2106,0y1<y2106)(0≤�1<�2≤106,0≤�1<�2≤106) — coordinates of the bottom left and the top right corners of the white sheet.

The second line of the input contains four integers x3,y3,x4,y4�3,�3,�4,�4 (0x3<x4106,0y3<y4106)(0≤�3<�4≤106,0≤�3<�4≤106) — coordinates of the bottom left and the top right corners of the first black sheet.

The third line of the input contains four integers x5,y5,x6,y6�5,�5,�6,�6 (0x5<x6106,0y5<y6106)(0≤�5<�6≤106,0≤�5<�6≤106) — coordinates of the bottom left and the top right corners of the second black sheet.

The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.

Output

If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".

Examples
input
Copy
2 2 4 4
1 1 3 5
3 1 5 5
output
Copy
NO
input
Copy
3 3 7 5
0 0 4 6
0 0 7 4
output
Copy
YES
input
Copy
5 2 10 5
3 1 7 6
8 1 11 7
output
Copy
YES
input
Copy
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
output
Copy
YES
Note

In the first example the white sheet is fully covered by black sheets.

In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5,4.5)(6.5,4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 6;
long long x1[N], y[N], x2[N], y2[N];

long long intersect_area(int rect1, int rect2, int save) {
	long long max_x = min(x2[rect1], x2[rect2]);
	long long min_x = max(x1[rect1], x1[rect2]);
	long long x_diff = max_x - min_x;

	long long max_y = max(y[rect1], y[rect2]);
	long long min_y = min(y2[rect1], y2[rect2]);
	long long y_diff = min_y - max_y;

	if(x_diff < 0 || y_diff < 0)
		return 0;

	x2[save] = max_x;
	y2[save] = min_y;
	x1[save] = min_x;
	y[save] = max_y;

	return x_diff * y_diff;
}

long long rectangle_area() {
	return (x2[0] - x1[0]) * (y2[0] - y[0]);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
#endif

	for(int i = 0; i < 3; ++i)
		scanf("%lld %lld %lld %lld", x1 + i, y + i, x2 + i, y2 + i);

	long long _01 = intersect_area(0, 1, 3);
	long long _02 = intersect_area(0, 2, 4);
	long long _34 = intersect_area(3, 4, 5);

	if(_01 == rectangle_area() || _02 == rectangle_area())
		puts("NO");
	else if(_01 == 0 || _02 == 0)
		puts("YES");
	else if(_01 + _02 - _34 < rectangle_area())
		puts("YES");
	else
		puts("NO");

	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 2 4 4
1 1 3 5
3 1 5 5

Output

x
+
cmd
NO
Advertisements

Demonstration


Codeforcess Solution C. White Sheet-Solution in C, C++, Java, Python,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+