A. My Friend of Misery

Codeforces
IDCF10108A
Time3000ms
Memory256MB
Difficulty
English · Original
Formal · Original
With the SCPC2015 getting closer, Noura Boubou, SCPC Head of Media, was very busy to the extent of not having time to recharge her phone's credit balance. However, her best friend, Nicole, was kind enough to transfer her own credit for the sake of keeping Noura online 24/7. The phone credit transfer system in Syria works in the following way: Each successful transfer operation withdraws 25 extra credit units from the sender's balance, but it doesn't cost anything when a transfer operation is unsuccessful due to non sufficient credit balance. Given the log of credit transfer requests and the response from the system to each request, in the form: Amount of transfer, and result of operation (either successful or unsuccessful), can you find out the number of possible initial credit balance values that Nicole could have had which satisfy the given log file? Note that the initial credit balance is always a non negative integer. The first line of input contains an integer T (1 ≤ T ≤ 256), the number of test cases. The first line of each test case contains an integer N (1 ≤ N ≤ 105), the number of operations in the log of credit transfer requests. Each of the following N lines contains an integer mi (1 ≤ mi ≤ 106), the amount of credit to transfer, followed by . Each log contains at least one unsuccessful operation. For each test case, print a single line that contains the number of possible initial credit balance values that Nicole could have had. Warning: large Input/Output data, be careful with certain languages. ## Input The first line of input contains an integer T (1 ≤ T ≤ 256), the number of test cases.The first line of each test case contains an integer N (1 ≤ N ≤ 105), the number of operations in the log of credit transfer requests.Each of the following N lines contains an integer mi (1 ≤ mi ≤ 106), the amount of credit to transfer, followed by . { + } denotes a successful operation. { - } denotes an unsuccessful operation. Each log contains at least one unsuccessful operation. ## Output For each test case, print a single line that contains the number of possible initial credit balance values that Nicole could have had. [samples] ## Note Warning: large Input/Output data, be careful with certain languages.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case $ k \in \{1, \dots, T\} $: - Let $ N_k \in \mathbb{Z} $ be the number of operations. - Let $ M_k = (m_{k,1}, m_{k,2}, \dots, m_{k,N_k}) $ be a sequence of transfer amounts. - Let $ R_k = (r_{k,1}, r_{k,2}, \dots, r_{k,N_k}) $ be a sequence of results, where $ r_{k,i} \in \{\text{successful}, \text{unsuccessful}\} $. **Constraints** 1. $ 1 \le T \le 256 $ 2. For each $ k \in \{1, \dots, T\} $: - $ 1 \le N_k \le 10^5 $ - $ 1 \le m_{k,i} \le 10^6 $ for all $ i \in \{1, \dots, N_k\} $ - Each log contains at least one unsuccessful operation. 3. A successful transfer deducts $ m_{k,i} + 25 $ from the sender’s balance. 4. An unsuccessful transfer deducts nothing. 5. Initial credit balance $ B_0 \in \mathbb{Z}_{\ge 0} $. **Objective** For each test case $ k $, determine the number of possible initial balances $ B_0 $ such that: - For each operation $ i $: - If $ r_{k,i} = \text{successful} $, then $ B_{i-1} \ge m_{k,i} + 25 $, and $ B_i = B_{i-1} - (m_{k,i} + 25) $. - If $ r_{k,i} = \text{unsuccessful} $, then $ B_{i-1} < m_{k,i} + 25 $, and $ B_i = B_{i-1} $. - $ B_i \ge 0 $ for all $ i $. Let $ S_k $ be the set of all possible $ B_0 $ satisfying the above. Compute $ |S_k| $.
API Response (JSON)
{
  "problem": {
    "name": "A. My Friend of Misery",
    "description": {
      "content": "With the SCPC2015 getting closer, Noura Boubou, SCPC Head of Media, was very busy to the extent of not having time to recharge her phone's credit balance. However, her best friend, Nicole, was kind en",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10108A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "With the SCPC2015 getting closer, Noura Boubou, SCPC Head of Media, was very busy to the extent of not having time to recharge her phone's credit balance. However, her best friend, Nicole, was kind en...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ N_k \\in \\mathbb{Z} $ be the number of operations.  \n- Let $ M_k = (m_{...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments