B. Baby name

Codeforces
IDCF10270B
Time1000ms
Memory512MB
Difficulty
English · Original
Formal · Original
A cute couple is gonna have a new baby soon, they don't know yet how they will name their baby. However, they want the name of the baby to be the concatenation of a non-empty substring of the father's name and a non-empty substring of the mother's name. Formally, let $a = a_1 a_2... a_n$ be the name of the father and $b = b_1 b_2... b_m$ be the name of the mother, the name of the baby will be $a_i a_{i + 1}... a_{i + s} b_j b_{j + 1}... b_{j + t}$, where $1 <= i <= i + s <= n$ and $1 <= j <= j + t <= m$. Both the mother and the father, are UNAL alumni. They know that having a name at the end of the course list in alphabetic order is very advantageous because that person is always the last being called, which means having more time to arrive to the class, to deliver homework, to prepare presentations, and so on. To determine which of the two names is higher alphabetically, their first letters are compared. If they differ, then the name whose first letter comes later in the alphabet is higher than the other name. If the first letters are the same, then the second letters are compared, and so on. If a position is reached where one name has no more letters to compare while the other does, then the largest name is the higher alphabetically. For example, _andres_ is higher alphabetically than _ana_, _andre_ and _andrea_, but it is lower than _cadie_, _andy_ and _andresito_. The couple knows that in the future the baby will study at UNAL, and of course, they want to help the baby to do very well. Considering this, they want the name of the baby to be the highest alphabetically possible. Given the name of the father and the name of the mother, what should be the name for the baby? The input consist of 2 lines, first line contains the name of the father and the second name contains the name of the mother. Each name is a non-empty string consisting of at most $2 * 10^5$ lowercase english characters. Print one line with the name of the baby. ## Input The input consist of 2 lines, first line contains the name of the father and the second name contains the name of the mother.Each name is a non-empty string consisting of at most $2 * 10^5$ lowercase english characters. ## Output Print one line with the name of the baby. [samples]
Let $ n, x, y \in \mathbb{Z} $ with $ 1 \le x, y < n \le 10^6 $. Let $ p \in \{1, 2, \dots, n\} $ denote Deja’s position in the queue (one-indexed). **Constraints:** - At least $ x $ people ahead of Deja: $ p - 1 \ge x $ ⟹ $ p \ge x + 1 $ - At most $ y $ people behind Deja: $ n - p \le y $ ⟹ $ p \ge n - y $ **Objective:** Find the number of integer positions $ p $ satisfying: $$ \max(x + 1, n - y) \le p \le n $$ The number of valid positions is: $$ n - \max(x + 1, n - y) + 1 $$
API Response (JSON)
{
  "problem": {
    "name": "B. Baby name",
    "description": {
      "content": "A cute couple is gonna have a new baby soon, they don't know yet how they will name their baby. However, they want the name of the baby to be the concatenation of a non-empty substring of the father's",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10270B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A cute couple is gonna have a new baby soon, they don't know yet how they will name their baby. However, they want the name of the baby to be the concatenation of a non-empty substring of the father's...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ n, x, y \\in \\mathbb{Z} $ with $ 1 \\le x, y < n \\le 10^6 $.\n\nLet $ p \\in \\{1, 2, \\dots, n\\} $ denote Deja’s position in the queue (one-indexed).\n\n**Constraints:**\n- At least $ x $ people ahead of...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments