1800B.md (2317B)
1 Source: https://codeforces.com/problemset/problem/1800/B 2 3 B. Count the Number of Pairs 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Kristina has a string $s$ of length $n$, consisting only of lowercase and uppercase Latin letters. For each pair of lowercase letter and its matching uppercase letter, Kristina can get $1$ burl. However, pairs of characters cannot overlap, so each character can only be in one pair. 22 23 For example, if she has the string $s$ = "aAaaBACacbE", she can get a burl for the following character pairs: 24 25 * $s_1$ = "a" and $s_2$ = "A" 26 * $s_4$ = "a" and $s_6$ = "A" 27 * $s_5$ = "B" and $s_{10}$ = "b" 28 * $s_7$= "C" and $s_9$ = "c" 29 30 Kristina wants to get more burles for her string, so she is going to perform no more than $k$ operations on it. In one operation, she can: 31 32 * either select the lowercase character $s_i$ ($1 \le i \le n$) and make it uppercase. 33 * or select uppercase character $s_i$ ($1 \le i \le n$) and make it lowercase. 34 35 For example, when $k$ = 2 and $s$ = "aAaaBACacbE" it can perform one operation: choose $s_3$ = "a" and make it uppercase. Then she will get another pair of $s_3$ = "A" and $s_8$ = "a" 36 37 Find maximum number of burles Kristina can get for her string. 38 39 Input 40 41 The first line of input data contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. 42 43 The description of the test cases follows. 44 45 The first line of each test case contains two integers $n$ ($1 \le n \le 2 \cdot 10^5$) and $k$ ($0 \le k \le n$) — the number of characters in the string and the maximum number of operations that can be performed on it. 46 47 The second line of each test case contains a string $s$ of length $n$, consisting only of lowercase and uppercase Latin letters. 48 49 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 50 51 Output 52 53 For each test case, print exactly one integer on a separate line: the maximum number of burles that Kristina can get for her string $s$. 54 55 Example 56 57 Input 58 59 ``` 60 5 61 62 11 2 63 64 aAaaBACacbE 65 66 2 2 67 68 ab 69 70 4 1 71 72 aaBB 73 74 6 0 75 76 abBAcC 77 78 5 3 79 80 cbccb 81 ``` 82 83 Output 84 85 ``` 86 5 87 0 88 1 89 3 90 2 91 ``` 92 93 Note 94 95 The first test case is explained in the problem statement. 96 97 In the second test case, it is not possible to get any pair by performing any number of operations.