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;
}
相关推荐
独断万古他化2 分钟前
【算法通关】前缀和:和为 K、和被 K整除、连续数组、矩阵区域和全解
算法·前缀和·矩阵·哈希表
历程里程碑4 分钟前
普通数组-----除了自身以外数组的乘积
大数据·javascript·python·算法·elasticsearch·搜索引擎·flask
AI视觉网奇7 分钟前
blender 导入fbx 黑色骨骼
学习·算法·ue5·blender
weixin_4684668511 分钟前
目标识别精度指标与IoU及置信度关系辨析
人工智能·深度学习·算法·yolo·图像识别·目标识别·调参
多恩Stone15 分钟前
【3D AICG 系列-8】PartUV 流程图详解
人工智能·算法·3d·aigc·流程图
铸人20 分钟前
再论自然数全加和-质数的规律
数学·算法·数论·复数
历程里程碑1 小时前
Linux22 文件系统
linux·运维·c语言·开发语言·数据结构·c++·算法
你撅嘴真丑9 小时前
第九章-数字三角形
算法
uesowys9 小时前
Apache Spark算法开发指导-One-vs-Rest classifier
人工智能·算法·spark
ValhallaCoder9 小时前
hot100-二叉树I
数据结构·python·算法·二叉树