C. Cheat Sheet

Codeforces
IDCF10262C
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
University of Shanghai for Science and Technology starts a course called *Film Appreciation of Black Album* recently. To be the best "Blackologist" in the university, Setsuna is actively preparing for the exam. The examination of the course is open book; that is to say, you can only take one single-sided cheat sheet to the exam. The cheat sheet can write $n$ characters at most. Setsuna has $m$ keywords that she wants to write on the cheat sheet. Her memory is not very good, so there may be some duplicate keywords. Each keyword consists of several visible characters(visible characters refer to characters with ASCII code between $33$ and $126$ inclusive). For both readability and neatness, keywords written on the cheat sheet should be separated by at least one space and must be different from each other. Setsuna wants to know how many *distinct* keywords she can write down on the cheat sheet at most. Uppercase and lowercase letters are considered different characters. The first line contains two integers $n, m (1 <= n, m <= 1000)$. The second line contains $m$ keywords separated by exactly one space. The length of each keyword is no more than $100$. It is guaranteed that keyword only consists of visible characters. Output one integer indicating the answer. In sample $1$, it takes $42$ characters to write all the words down. So Setsuna can write down at most four. In sample $2$, there is only one keyword. ## Input The first line contains two integers $n, m (1 <= n, m <= 1000)$.The second line contains $m$ keywords separated by exactly one space. The length of each keyword is no more than $100$. It is guaranteed that keyword only consists of visible characters. ## Output Output one integer indicating the answer. [samples] ## Note In sample $1$, it takes $42$ characters to write all the words down. So Setsuna can write down at most four.In sample $2$, there is only one keyword.
**Definitions** Let $ N, M \in \mathbb{Z}^+ $ denote the number of subjects and operations, respectively. Let $ A = (a_1, a_2, \dots, a_N) \in \mathbb{Z}^N $ be the initial marks vector. For each operation $ j \in \{1, \dots, M\} $, let $ (B_j, C_j) \in \mathbb{Z}^+ \times \mathbb{Z}^+ $ denote the maximum number of subjects that can be modified and the replacement value, respectively. **Constraints** 1. $ 1 \le N, M \le 10^5 $ 2. $ 1 \le a_i \le 10^9 $ for all $ i \in \{1, \dots, N\} $ 3. $ 1 \le B_j \le N $, $ 1 \le C_j \le 10^9 $ for all $ j \in \{1, \dots, M\} $ **Objective** Perform operations $ j = 1 $ to $ M $ in order. In operation $ j $, choose at most $ B_j $ subjects and set their marks to $ C_j $. Maximize the final sum $ S = \sum_{i=1}^N a_i' $, where $ a_i' $ is the final mark of subject $ i $. **Key Insight** To maximize the sum, greedily replace the smallest current marks with the largest available $ C_j $, but operations are sequential and must be applied in order. Thus, for each operation $ j $, replace up to $ B_j $ subjects with the smallest current marks (if $ C_j $ is greater than those marks). **Formal Objective** Compute the maximum possible sum after sequentially applying the $ M $ operations, where in operation $ j $, we may replace at most $ B_j $ of the current smallest marks with $ C_j $, in order.
API Response (JSON)
{
  "problem": {
    "name": "C. Cheat Sheet",
    "description": {
      "content": "University of Shanghai for Science and Technology starts a course called *Film Appreciation of Black Album* recently. To be the best \"Blackologist\"  in the university, Setsuna is actively preparing fo",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10262C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "University of Shanghai for Science and Technology starts a course called *Film Appreciation of Black Album* recently. To be the best \"Blackologist\"  in the university, Setsuna is actively preparing fo...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N, M \\in \\mathbb{Z}^+ $ denote the number of subjects and operations, respectively.  \nLet $ A = (a_1, a_2, \\dots, a_N) \\in \\mathbb{Z}^N $ be the initial marks vector.  \nFor eac...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments