K. Video Reviews

Codeforces
IDCF10175K
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
The studio «Lodka Gaming» is engaged in advertising of their new game «.C.O.N.T.E.S.T: Unexpected Behaviour». The studio's marketer is planning to communicate with n videobloggers one by one (in the predetermined order, starting from the 1-st and ending with the n-th), offering them to record a video review on the game. All people are different and videobloggers are as well, therefore the i-th videoblogger will record a review in two cases: either he is interested in this game, or there are already at least ai video reviews on this game. The studio wants to have at least m video reviews in the Internet. The game designer of «Lodka Gaming» understands these video reviews possibly would not appear by themselves, so he wants to _convince_ some video bloggers that they are actually interested in this game. Which minimal number of videobloggers are needed to be _convinced_? The first line contains two integers n and m (1 ≤ n ≤ 200000, 1 ≤ m ≤ n) — the number of videobloggers and the required number of video reviews. The second line contains n integers ai (0 ≤ ai ≤ 200000) — the minimal number of video reviews that should appear in the Internet so that the i-th videoblogger will record a review in case he is not interested in the game. Output a single integer — the minimal number of videobloggers who have to be _convinced_ to record a video review on the game in order to achieve at least m total video reviews in the Internet. ## Input The first line contains two integers n and m (1 ≤ n ≤ 200000, 1 ≤ m ≤ n) — the number of videobloggers and the required number of video reviews.The second line contains n integers ai (0 ≤ ai ≤ 200000) — the minimal number of video reviews that should appear in the Internet so that the i-th videoblogger will record a review in case he is not interested in the game. ## Output Output a single integer — the minimal number of videobloggers who have to be _convinced_ to record a video review on the game in order to achieve at least m total video reviews in the Internet. [samples]
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ with $ 1 \leq m \leq n $. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of non-negative integers, where $ a_i $ is the threshold for the $ i $-th videoblogger. Let $ x_i \in \{0,1\} $ indicate whether the $ i $-th videoblogger is **convinced** ($ x_i = 1 $) or not ($ x_i = 0 $). Let $ r_i \in \{0,1\} $ indicate whether the $ i $-th videoblogger **records** a review, defined as: $$ r_i = \begin{cases} 1 & \text{if } x_i = 1 \text{ or } \sum_{j=1}^{i-1} r_j \geq a_i \\ 0 & \text{otherwise} \end{cases} $$ **Constraints** 1. $ 1 \leq n \leq 200000 $ 2. $ 1 \leq m \leq n $ 3. $ 0 \leq a_i \leq 200000 $ for all $ i \in \{1, \dots, n\} $ 4. $ \sum_{i=1}^n r_i \geq m $ **Objective** Minimize $ \sum_{i=1}^n x_i $, subject to the above constraints.
API Response (JSON)
{
  "problem": {
    "name": "K. Video Reviews",
    "description": {
      "content": "The studio «Lodka Gaming» is engaged in advertising of their new game «.C.O.N.T.E.S.T: Unexpected Behaviour». The studio's marketer is planning to communicate with n videobloggers one by one (in the p",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10175K"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The studio «Lodka Gaming» is engaged in advertising of their new game «.C.O.N.T.E.S.T: Unexpected Behaviour». The studio's marketer is planning to communicate with n videobloggers one by one (in the p...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ with $ 1 \\leq m \\leq n $.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of non-negative integers, where $ a_i $ is the threshold for the $ i $-th v...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments