M. Make Cents?

Codeforces
IDCF10135M
Time6000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this year, but that’s irrelephant. What’s important is that the location of the competition might not have been the same every year. Therefore, after every trip, he always has leftover money in the currency of the country he visited. Now he wants to see how much Jordanian Dinars he has after all those competitions. Can you help him convert the leftover money from all competitions to Jordanian Dinar, if that makes any cents? The first line of input is T – the number of test cases. The first line of each test case contains C and N (1 ≤ C, N ≤ 100000), the number of currency types and the number of competitions, respectively. The next C lines each contain the name of the currency Ci of maximum length 10 in lowercase and/or uppercase letters, and the value Vi of that currency in Jordanian Dinar (0 < Vi ≤ 1000). The names are case-sensitive. The next N lines each contains an amount left over from each competition (0 ≤ Ni ≤ 1000), and the name of the currency of that amount (it is guaranteed that the name was either given in the input or is “JD”). For each test case, print on a single line the total amount of money he has in Jordanian Dinar(JD) rounded to 6 decimal digits. ## Input The first line of input is T – the number of test cases.The first line of each test case contains C and N (1 ≤ C, N ≤ 100000), the number of currency types and the number of competitions, respectively.The next C lines each contain the name of the currency Ci of maximum length 10 in lowercase and/or uppercase letters, and the value Vi of that currency in Jordanian Dinar (0 < Vi ≤ 1000). The names are case-sensitive.The next N lines each contains an amount left over from each competition (0 ≤ Ni ≤ 1000), and the name of the currency of that amount (it is guaranteed that the name was either given in the input or is “JD”). ## Output For each test case, print on a single line the total amount of money he has in Jordanian Dinar(JD) rounded to 6 decimal digits. [samples]
**Definitions** Let $ t \in \mathbb{Z} $ be the number of test cases. For each test case: - Let $ C \in \mathbb{Z} $ be the number of currency types, $ N \in \mathbb{Z} $ the number of competitions. - Let $ \mathcal{C} = \{ (name_i, v_i) \mid i \in \{1, \dots, C\} \} $ be a mapping from currency names to their values in Jordanian Dinar (JD), where $ v_i \in \mathbb{R}^+ $. - Let $ \mathcal{C}_{\text{JD}} = \mathcal{C} \cup \{ (\text{"JD"}, 1.0) \} $. - Let $ \mathcal{L} = \{ (a_j, c_j) \mid j \in \{1, \dots, N\} \} $ be a sequence of leftover amounts and their currency names, where $ a_j \in \mathbb{R}_{\geq 0} $, $ c_j \in \text{strings} $, and $ c_j \in \text{dom}(\mathcal{C}_{\text{JD}}) $. **Constraints** 1. $ 1 \leq t \leq 1000 $ 2. $ 1 \leq C, N \leq 100000 $ 3. For each currency: $ 0 < v_i \leq 1000 $, $ \text{len}(name_i) \leq 10 $ 4. For each leftover: $ 0 \leq a_j \leq 1000 $, $ c_j $ is a valid currency name in $ \mathcal{C}_{\text{JD}} $ **Objective** For each test case, compute the total amount in JD: $$ S = \sum_{j=1}^{N} a_j \cdot \mathcal{C}_{\text{JD}}(c_j) $$ Output $ S $ rounded to 6 decimal places.
API Response (JSON)
{
  "problem": {
    "name": "M. Make Cents?",
    "description": {
      "content": "Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this year, but that’s irrelephant. What’s important is that the location of the competition might not hav",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 6000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10135M"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this year, but that’s irrelephant. What’s important is that the location of the competition might not hav...",
      "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:  \n- Let $ C \\in \\mathbb{Z} $ be the number of currency types, $ N \\in \\mathbb{Z} $ the number of competiti...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments