B. Count the Number of Pairs
创始人
2024-05-28 12:41:54
0

原题链接

纯纯水一下;

昨天晚上的比赛,由于半夜打的,精神状态不好,wa了俩发直接睡觉去了,现在白天写写发现,不难,水中水

模拟题吧,题目怎么说就这么作

Kristina has a string ss of length nn, consisting only of lowercase and uppercase Latin letters. For each pair of lowercase letter and its matching uppercase letter, Kristina can get 11 burl. However, pairs of characters cannot overlap, so each character can only be in one pair.

For example, if she has the string ss = "aAaaBACacbE", she can get a burl for the following character pairs:

  • s1s1 = "a" and s2s2 = "A"
  • s4s4 = "a" and s6s6 = "A"
  • s5s5 = "B" and s10s10 = "b"
  • s7s7= "C" and s9s9 = "c"

Kristina wants to get more burles for her string, so she is going to perform no more than kk operations on it. In one operation, she can:

  • either select the lowercase character sisi (1≤i≤n1≤i≤n) and make it uppercase.
  • or select uppercase character sisi (1≤i≤n1≤i≤n) and make it lowercase.

For example, when kk = 2 and ss = "aAaaBACacbE" it can perform one operation: choose s3s3 = "a" and make it uppercase. Then she will get another pair of s3s3 = "A" and s8s8 = "a"

Find maximum number of burles Kristina can get for her string.

Input

The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains two integers nn (1≤n≤2⋅1051≤n≤2⋅105) and kk (0≤k≤n0≤k≤n) — the number of characters in the string and the maximum number of operations that can be performed on it.

The second line of each test case contains a string ss of length nn, consisting only of lowercase and uppercase Latin letters.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, print exactly one integer on a separate line: the maximum number of burles that Kristina can get for her string ss.

Example

input

Copy

 

5

11 2

aAaaBACacbE

2 2

ab

4 1

aaBB

6 0

abBAcC

5 3

cbccb

output

Copy

5
0
1
3
2

Note

The first test case is explained in the problem statement.

In the second test case, it is not possible to get any pair by performing any number of operations.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define dbug cout<<"hear!"<=b;i--)
#define pper(a,b) for(int j=a;j>=b;j--)
#define no cout<<"NO"<> t;while (t--){cin >> n >> m;string s;cin >> s;mapmp;rep(0, n - 1){mp[s[i]]++;}ans = 0;for (int i = 'A';i <= 'Z';i++){while (mp[i] && mp[i + 32]){ans++;mp[i]--;mp[i + 32]--;}}for (int i = 'A';i <= 'Z';i++){while (m > 0 && mp[i] - 2 >= 0){ans++;mp[i] -= 2;m--;}}for (int i = 'a';i <= 'z';i++){while (m > 0 && mp[i] - 2 >= 0){ans++;mp[i] -= 2;m--;}}cout << ans<

 

相关内容

热门资讯

【NI Multisim 14...   目录 序言 一、工具栏 🍊1.“标准”工具栏 🍊 2.视图工具...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
Android|无法访问或保存... 这个问题可能是由于权限设置不正确导致的。您需要在应用程序清单文件中添加以下代码来请求适当的权限:此外...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
AsusVivobook无法开... 首先,我们可以尝试重置BIOS(Basic Input/Output System)来解决这个问题。...
ASM贪吃蛇游戏-解决错误的问... 要解决ASM贪吃蛇游戏中的错误问题,你可以按照以下步骤进行:首先,确定错误的具体表现和问题所在。在贪...
月入8000+的steam搬砖... 大家好,我是阿阳 今天要给大家介绍的是 steam 游戏搬砖项目,目前...