M. Ahmad Jaber Rectangles

Codeforces
IDCF10203M
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Ahmad has two rectangles, both of them are above $x -a x i s$ and the height of each one is $h$ $(1 <= h <= 10^9)$. The first rectangle's sides are $(x_1, 0)$ $(x_2, 0)$ $(x_1, h)$ $(x_2, h)$ The second rectangle's sides are $(x_3, 0)$ $(x_4, 0)$ $(x_3, h)$ $(x_4, h)$ Ahmad wants to know what is the area of the intersection between these two rectangles. The first and the only line of input contains 5 integers $x_1$,$x_2$,$x_3$,$x_4$ and $h$ $(1 <= x_1 < x_2 <= 10^9)$ $(1 <= x_3 < x_4 <= 10^9)$ $(1 <= h <= 10^9)$. Print the area of intersection. ## Input The first and the only line of input contains 5 integers $x_1$,$x_2$,$x_3$,$x_4$ and $h$ $(1 <= x_1 < x_2 <= 10^9)$ $(1 <= x_3 < x_4 <= 10^9)$ $(1 <= h <= 10^9)$. ## Output Print the area of intersection. [samples]
**Definitions** Let $ x_1, x_2, x_3, x_4, h \in \mathbb{Z} $ be given integers such that: - $ 1 \le x_1 < x_2 \le 10^9 $ - $ 1 \le x_3 < x_4 \le 10^9 $ - $ 1 \le h \le 10^9 $ Let $ R_1 = [x_1, x_2] \times [0, h] $ and $ R_2 = [x_3, x_4] \times [0, h] $ be two axis-aligned rectangles. **Objective** Compute the area of the intersection $ R_1 \cap R_2 $: $$ \text{Area} = h \cdot \max(0, \min(x_2, x_4) - \max(x_1, x_3)) $$
API Response (JSON)
{
  "problem": {
    "name": "M. Ahmad Jaber Rectangles",
    "description": {
      "content": "Ahmad has two rectangles, both of them are above $x -a x i s$ and the height of each one is $h$ $(1 <= h <= 10^9)$. The first rectangle's sides are $(x_1, 0)$ $(x_2, 0)$ $(x_1, h)$ $(x_2, h)$ The se",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10203M"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Ahmad has two rectangles, both of them are above $x -a x i s$ and the height of each one is $h$ $(1 <= h <= 10^9)$.\n\nThe first rectangle's sides are $(x_1, 0)$ $(x_2, 0)$ $(x_1, h)$ $(x_2, h)$\n\nThe se...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ x_1, x_2, x_3, x_4, h \\in \\mathbb{Z} $ be given integers such that:  \n- $ 1 \\le x_1 < x_2 \\le 10^9 $  \n- $ 1 \\le x_3 < x_4 \\le 10^9 $  \n- $ 1 \\le h \\le 10^9 $  \n\nLet $ R_1 = [x...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments