C. Third-Party Software

Codeforces
IDCF10175C
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Pavel is developing a game. To do that, he needs functions available in a third-party library too famous to be called. It is known that the function i first appeared in version ai and existed until version bi, and starting from the version bi + 1, it is absent in this library. The library is not free and Pavel needs all the functions. Which minimal number of versions he need to purchase to be able to use all the functions? The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of the functions. Each of the next n lines contains two integers ai and bi (1 ≤ ai ≤ bi ≤ 109) — the interval of library versions where function i was available. In the first line output a single integer k — the minimal number of library versions need to be purchased to unlock all functions. In the second line output k distinct integers — the numbers of versions need to be purchased. If there are several possible answers, output any of them. ## Input The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of the functions.Each of the next n lines contains two integers ai and bi (1 ≤ ai ≤ bi ≤ 109) — the interval of library versions where function i was available. ## Output In the first line output a single integer k — the minimal number of library versions need to be purchased to unlock all functions.In the second line output k distinct integers — the numbers of versions need to be purchased.If there are several possible answers, output any of them. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of functions. For each $ i \in \{1, \dots, n\} $, let $ [a_i, b_i] \subseteq \mathbb{Z} $ be the interval of versions where function $ i $ is available, with $ 1 \leq a_i \leq b_i \leq 10^9 $. **Constraints** 1. $ 1 \leq n \leq 200000 $ 2. For all $ i \in \{1, \dots, n\} $: $ 1 \leq a_i \leq b_i \leq 10^9 $ **Objective** Find the minimal cardinality set $ S \subseteq \mathbb{Z} $ such that for every $ i \in \{1, \dots, n\} $, there exists $ s \in S $ with $ s \in [a_i, b_i] $. Output $ |S| $ and any such set $ S $.
API Response (JSON)
{
  "problem": {
    "name": "C. Third-Party Software",
    "description": {
      "content": "Pavel is developing a game. To do that, he needs functions available in a third-party library too famous to be called. It is known that the function i first appeared in version ai and existed until ve",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10175C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Pavel is developing a game. To do that, he needs functions available in a third-party library too famous to be called. It is known that the function i first appeared in version ai and existed until ve...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of functions.  \nFor each $ i \\in \\{1, \\dots, n\\} $, let $ [a_i, b_i] \\subseteq \\mathbb{Z} $ be the interval of versions where function $ i $ ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments