Wednesday, March 30, 2022

Binary String Cost

 According to the new tax scheme, a new tax called the binary string tax was introduced! JJ has a binary string 

of length . According to the tax scheme, for every occurrence of in , a tax of rupees will be charged, while for every occurrence of in , a tax of

rupees will be charged.

For example, if

, and , then has occurrence of and occurrences of , so the tax charged

JJ can rearrange the string

in any way he wants. He wants to minimize the amount of tax he has to pay. Can you help him do so?

Input Format

  • The first line contains a single integer
  • - the number of test cases. Then the test cases follow.
  • The first line of each test case contains three integers
  • , and - the length of the binary string , the tax charged on an occurrence of and the tax charged on an occurrence of
  • .
  • The second line of each test case contains a binary string
  • of length containing s and
    • s only.

    Output Format

    For each test case, output the minimum amount of tax that JJ has to pay.

    Constraints

    Sample Input 1

    2
    4 7 3
    1101
    5 3 4
    00000
    

    Sample Output 1

    3
    0
    

    Explanation

    Test Case 1: JJ can rearrange

    to for which the tax charged will be

    which is the minimum value of tax.

    Test Case 2: The tax charged for the string

    is which can not be reduced further.

    No comments:

    Post a Comment

    मुझे दिल में बसाना आसान नहीं....

    पता है Recently i realised की मुझे दिल में बसाना आसान नहीं है बात-बात पे चिढ़ जाती हूं मैं दिल लगा लूं एक बार तो फिर ज़िद पे अड़...