{"problem":{"name":"G. Repair","description":{"content":"Alex is repairing his country house. He has a rectangular metal sheet of size a × b. He has to cut two rectangular sheets of sizes a1 × b1 and a2 × b2 from it. All cuts must be parallel to the sides o","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10097G"},"statements":[{"statement_type":"Markdown","content":"Alex is repairing his country house. He has a rectangular metal sheet of size a × b. He has to cut two rectangular sheets of sizes a1 × b1 and a2 × b2 from it. All cuts must be parallel to the sides of the initial sheet. Determine if he can do it.\n\nThe first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109) — the sizes of the initial sheet.\n\nThe second line contains two space-separated integers a1 and b1 (1 ≤ a1, b1 ≤ 109) — the sizes of the first sheet to cut out.\n\nThe third line contains two space-separated integers a2 and b2 (1 ≤ a2, b2 ≤ 109) — the sizes of the second sheet to cut out.\n\nOutput «_YES_» (without quotes), if it's possible to cut two described sheets from the initial sheet, or «_NO_» (without quotes), if it's not possible.\n\n## Input\n\nThe first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109) — the sizes of the initial sheet.The second line contains two space-separated integers a1 and b1 (1 ≤ a1, b1 ≤ 109) — the sizes of the first sheet to cut out.The third line contains two space-separated integers a2 and b2 (1 ≤ a2, b2 ≤ 109) — the sizes of the second sheet to cut out.\n\n## Output\n\nOutput «_YES_» (without quotes), if it's possible to cut two described sheets from the initial sheet, or «_NO_» (without quotes), if it's not possible.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ a, b \\in \\mathbb{Z}^+ $ be the dimensions of the initial rectangular sheet.  \nLet $ (a_1, b_1), (a_2, b_2) \\in \\mathbb{Z}^+ \\times \\mathbb{Z}^+ $ be the dimensions of the two target rectangles.  \n\nFor each target rectangle, rotation is allowed: i.e., $ (a_i, b_i) $ may be used as $ (b_i, a_i) $.  \n\n**Constraints**  \n1. $ 1 \\leq a, b \\leq 10^9 $  \n2. $ 1 \\leq a_1, b_1, a_2, b_2 \\leq 10^9 $  \n\n**Objective**  \nDetermine whether there exist orientations $ o_1, o_2 \\in \\{0, 1\\} $ such that the two rectangles  \n$ R_1 = (a_1^{o_1}, b_1^{o_1}) $ and $ R_2 = (a_2^{o_2}, b_2^{o_2}) $,  \nwhere  \n$$\nx^0 = x, \\quad x^1 = y, \\quad y^0 = y, \\quad y^1 = x\n$$  \ncan be placed non-overlappingly and entirely within the $ a \\times b $ rectangle, with sides parallel to the axes.  \n\nThat is, determine if there exists a way to partition the $ a \\times b $ rectangle (via axis-aligned placement) to contain both $ R_1 $ and $ R_2 $ without overlap.  \n\n**Feasibility Conditions**  \nDefine the set of possible orientations:  \n- $ O_1 = \\{ (a_1, b_1), (b_1, a_1) \\} $  \n- $ O_2 = \\{ (a_2, b_2), (b_2, a_2) \\} $  \n\nThen, output \"YES\" if there exist $ (w_1, h_1) \\in O_1 $, $ (w_2, h_2) \\in O_2 $, such that **at least one** of the following holds:  \n\n1. **Side-by-side horizontally**:  \n   $ w_1 + w_2 \\leq a $ and $ \\max(h_1, h_2) \\leq b $  \n\n2. **Stacked vertically**:  \n   $ h_1 + h_2 \\leq b $ and $ \\max(w_1, w_2) \\leq a $  \n\n3. **L-shaped (w1 + w2 ≤ a, h1 + h2 ≤ b, with one placed beside and above the other)**:  \n   $ w_1 + w_2 \\leq a $ and $ h_1 + h_2 \\leq b $ and $ w_1 \\leq a $, $ w_2 \\leq a $, $ h_1 \\leq b $, $ h_2 \\leq b $  \n   *(Note: This is implied by the above two if we allow arbitrary placement; however, in axis-aligned non-overlapping packing of two rectangles into a bounding rectangle, the only viable configurations are side-by-side, stacked, or one placed beside and above — which reduces to checking the two above plus two more:)*  \n\nActually, to be complete, also check:  \n\n4. $ w_1 + h_2 \\leq a $ and $ h_1 + w_2 \\leq b $  (one rotated to fit beside and above)  \n5. $ w_2 + h_1 \\leq a $ and $ h_2 + w_1 \\leq b $  \n\nBut the standard and sufficient approach is to check all 4 combinations of orientations, and for each, check:  \n\n- Horizontal arrangement: $ w_1 + w_2 \\leq a $ and $ \\max(h_1, h_2) \\leq b $  \n- Vertical arrangement: $ h_1 + h_2 \\leq b $ and $ \\max(w_1, w_2) \\leq a $  \n- “L”-shaped: $ w_1 + w_2 \\leq a $ and $ h_1 + h_2 \\leq b $ — **but this is NOT sufficient alone**  \n\nActually, the **correct and complete set** of configurations to check for two rectangles in a bounding rectangle is:  \n\nFor each $ (w_1, h_1) \\in O_1 $, $ (w_2, h_2) \\in O_2 $:  \n- **Side-by-side**: $ w_1 + w_2 \\leq a $ and $ h_1 \\leq b $ and $ h_2 \\leq b $ and $ \\max(h_1, h_2) \\leq b $  \n- **Stacked**: $ h_1 + h_2 \\leq b $ and $ w_1 \\leq a $ and $ w_2 \\leq a $ and $ \\max(w_1, w_2) \\leq a $  \n- **One beside, one above (L-shape)**:  \n  - $ w_1 + w_2 \\leq a $ and $ h_1 + h_2 \\leq b $  \n  - **AND** $ w_1 \\leq a $, $ w_2 \\leq a $, $ h_1 \\leq b $, $ h_2 \\leq b $ — always true if above holds  \n\nBut the L-shape requires:  \nEither:  \n- $ w_1 + w_2 \\leq a $ and $ h_1 + h_2 \\leq b $  \n  (This allows placing one rectangle to the right of the other, and one above the other — but only if they are arranged in an L, meaning one is placed in corner, the other in adjacent corner — which is valid if the bounding box is $ \\max(w_1, w_2) \\times \\max(h_1, h_2) $, which is **not** the case)  \n\nActually, **the only two valid configurations** are:  \n\n- **Horizontal**: total width $ w_1 + w_2 \\leq a $, height $ \\max(h_1, h_2) \\leq b $  \n- **Vertical**: total height $ h_1 + h_2 \\leq b $, width $ \\max(w_1, w_2) \\leq a $  \n- **Mixed (L-shape)**:  \n  - $ w_1 + h_2 \\leq a $ and $ h_1 + w_2 \\leq b $  \n  - $ w_2 + h_1 \\leq a $ and $ h_2 + w_1 \\leq b $  \n\nSo in total, for each of the 4 orientation pairs, check:  \n\n1. $ w_1 + w_2 \\leq a $ and $ \\max(h_1, h_2) \\leq b $  \n2. $ h_1 + h_2 \\leq b $ and $ \\max(w_1, w_2) \\leq a $  \n3. $ w_1 + h_2 \\leq a $ and $ h_1 + w_2 \\leq b $  \n4. $ w_2 + h_1 \\leq a $ and $ h_2 + w_1 \\leq b $  \n\nBut (3) and (4) are redundant if we consider all 4 orientation combinations — since $ (w_1, h_1) $ and $ (w_2, h_2) $ already include both orientations.  \n\nThus, simply iterate over all 4 combinations of orientations, and for each, check:  \n\n- $ w_1 + w_2 \\leq a $ and $ \\max(h_1, h_2) \\leq b $  \n- $ h_1 + h_2 \\leq b $ and $ \\max(w_1, w_2) \\leq a $  \n\n**Final Objective**  \n$$\n\\exists \\, (w_1, h_1) \\in \\{(a_1, b_1), (b_1, a_1)\\}, \\quad (w_2, h_2) \\in \\{(a_2, b_2), (b_2, a_2)\\}\n$$  \nsuch that  \n$$\n(w_1 + w_2 \\leq a \\land \\max(h_1, h_2) \\leq b) \\quad \\lor \\quad (h_1 + h_2 \\leq b \\land \\max(w_1, w_2) \\leq a)\n$$  \n\nOutput \"YES\" if true, \"NO\" otherwise.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10097G","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}