J. Beautiful Triangles

Codeforces
IDCF10148J
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Sancho loves geometry. And he loves triangles even more, to the point of developing his own metric of beauty for triangles. In his metric, the beauty of a triangle is calculated by subtracting the length of the largest side from the sum of the lengths of the other two sides. During weekends, Sancho likes to walk by the beach looking for straight sticks to build his triangles. He has already found 2 sticks and he's very optimistic about the triangle he's going to build. He wants to know what should be the length of the third stick so that the beauty of his triangle is maximized. Help him with this task! The input consists of a single line, containing two integers l1 and l2 (1 ≤ l1, l2 ≤ 2 × 109) indicating the length of the sticks that Sancho has already found. Output a single integer: the length of the third stick that maximizes the beauty of the triangle that Sancho is going to build. ## Input The input consists of a single line, containing two integers l1 and l2 (1 ≤ l1, l2 ≤ 2 × 109) indicating the length of the sticks that Sancho has already found. ## Output Output a single integer: the length of the third stick that maximizes the beauty of the triangle that Sancho is going to build. [samples]
Let $ l_1, l_2 \in \mathbb{Z}^+ $ be the lengths of the two given sticks, with $ 1 \leq l_1, l_2 \leq 2 \times 10^9 $. Let $ x \in \mathbb{R}^+ $ be the length of the third stick. The beauty of the triangle is defined as: $$ B(x) = (l_1 + l_2 + x) - 2 \cdot \max(l_1, l_2, x) $$ Subject to the triangle inequality: $$ x < l_1 + l_2, \quad l_1 < l_2 + x, \quad l_2 < l_1 + x $$ **Objective**: Find $ x \in \mathbb{R}^+ $ that maximizes $ B(x) $, under the triangle inequality constraints.
API Response (JSON)
{
  "problem": {
    "name": "J. Beautiful Triangles",
    "description": {
      "content": "Sancho loves geometry. And he loves triangles even more, to the point of developing his own metric of beauty for triangles. In his metric, the beauty of a triangle is calculated by subtracting the len",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10148J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Sancho loves geometry. And he loves triangles even more, to the point of developing his own metric of beauty for triangles. In his metric, the beauty of a triangle is calculated by subtracting the len...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ l_1, l_2 \\in \\mathbb{Z}^+ $ be the lengths of the two given sticks, with $ 1 \\leq l_1, l_2 \\leq 2 \\times 10^9 $.\n\nLet $ x \\in \\mathbb{R}^+ $ be the length of the third stick.\n\nThe beauty of the ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments