[Solution] Split The String CodeChef Solution
Problem
For a binary string , let denote its badness, defined to be the difference between the number of zeros and number of ones present in it. That is, if the string has zeros and ones, its badness is . For example, the badness of "" is , the badness of "" is , the badness of "" is , and the badness of the empty string is .
You are given an integer and a binary string .
You would like to partition into disjoint subsequences (some of which may be empty), such that the maximum badness among all these subsequences is minimized. Find this value.
Formally,
- Let be a partition of into disjoint subsequences. Every character of must appear in one of the .
- Some of the
- may be empty.
- Then, find the minimum value of across all possible choices of satisfying the first condition.
Is it hot or cold CodeChef Solution
Maximise the Tastiness CodeChef Solution
N Buttons 1 Bulb CodeChef Solution
Valid Minimum CodeChef Solution
High Frequency CodeChef Solution
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- The description of each test case is as follows:
- The first line contains two space-separated integers and .
- The second line contains the binary string of length .
Output Format
For each test case, print the minimum possible value of the maximum badness when is partitioned into subsequences.
Explanation:
Test case : Let's take a couple of examples.
- Suppose the partition is , obtained as (elements of one color form a subsequence). The respective badness values are , the maximum of which is .
- Suppose the partition is , obtained as . The respective badness values are , the maximum of which is .
The first partition, with a maximum badness of , is one of the optimal partitions.
Test case : The only possible partition is , which has a badness of .
Test case : The partitions and both lead to a badness of , which is the minimum possible.
No comments:
Post a Comment