A. Problem Generator

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vlad is planning to hold m𝑚 rounds next month. Each round should contain one problem of difficulty levels 'A', 'B', 'C', 'D', 'E', 'F', and 'G'.

Vlad already has a bank of n𝑛 problems, where the i𝑖-th problem has a difficulty level of ai𝑎𝑖. There may not be enough of these problems, so he may have to come up with a few more problems.

Vlad wants to come up with as few problems as possible, so he asks you to find the minimum number of problems he needs to come up with in order to hold m𝑚 rounds.

For example, if m=1𝑚=1, n=10𝑛=10, a=𝑎= 'BGECDCBDED', then he needs to come up with two problems: one of difficulty level 'A' and one of difficulty level 'F'.

Input

The first line contains a single integer t𝑡 (1≤t≤10001≤𝑡≤1000) --- the number of test cases.

The first line of each test case contains two integers n𝑛 and m𝑚 (1≤n≤501≤𝑛≤50, 1≤m≤51≤𝑚≤5) --- the number of problems in the bank and the number of upcoming rounds, respectively.

The second line of each test case contains a string a𝑎 of n𝑛 characters from 'A' to 'G' --- the difficulties of the problems in the bank.

Output

For each test case, output a single integer --- the minimum number of problems that need to come up with to hold m𝑚 rounds.

Example

input

Copy

复制代码

3

10 1

BGECDCBDED

10 2

BGECDCBDED

9 1

BBCDEFFGG

output

Copy

复制代码
2
5
1

解题说明:此题是一道模拟器,因为每一轮都必须要出现A-G这几个字母,所以直接统计当前已出现的字母,然后判断每一轮中是否漏字母即可,最后求和。

cpp 复制代码
#include<stdio.h>

int main()
{
	int test;
	scanf("%d", &test);
	while (test--)
	{
		int a;
		int temp[7] = { 0 };
		int b;
		scanf("%d%d", &a, &b);
		char t[55];
		scanf(" %s", t);
		for (int i = 0; i < a; i++)
		{
			temp[t[i] - 65]++;
		}
		int count = 0;
		for (int i = 0; i < 7; i++)
		{
			if ((temp[i]) < b)
			{
				count += (b - (temp[i]));
			}
		}
		printf("%d\n", count);
	}
	return 0;
}
相关推荐
带娃的IT创业者几秒前
如何开发一个教育性质的多线程密码猜测演示器
网络·python·算法
Aczone281 小时前
硬件(六)arm指令
开发语言·汇编·arm开发·嵌入式硬件·算法
luckys.one6 小时前
第9篇:Freqtrade量化交易之config.json 基础入门与初始化
javascript·数据库·python·mysql·算法·json·区块链
~|Bernard|7 小时前
在 PyCharm 里怎么“点鼠标”完成指令同样的运行操作
算法·conda
战术摸鱼大师7 小时前
电机控制(四)-级联PID控制器与参数整定(MATLAB&Simulink)
算法·matlab·运动控制·电机控制
Christo37 小时前
TFS-2018《On the convergence of the sparse possibilistic c-means algorithm》
人工智能·算法·机器学习·数据挖掘
好家伙VCC8 小时前
数学建模模型 全网最全 数学建模常见算法汇总 含代码分析讲解
大数据·嵌入式硬件·算法·数学建模
liulilittle10 小时前
IP校验和算法:从网络协议到SIMD深度优化
网络·c++·网络协议·tcp/ip·算法·ip·通信
bkspiderx11 小时前
C++经典的数据结构与算法之经典算法思想:贪心算法(Greedy)
数据结构·c++·算法·贪心算法
中华小当家呐13 小时前
算法之常见八大排序
数据结构·算法·排序算法