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 分钟前
【算法训练营Day32】图论专题
算法·深度优先·图论
小欣加油8 分钟前
leetcode 174 地下城游戏
c++·算法·leetcode·职场和发展·动态规划
sali-tec19 分钟前
C# 基于OpenCv的视觉工作流-章11-高斯滤波
图像处理·人工智能·opencv·算法·计算机视觉
不知名XL31 分钟前
day23 贪心算法 part01
算法·贪心算法
wuqingshun3141591 小时前
蓝桥杯 缺页异常2【算法赛】
算法·职场和发展·蓝桥杯
Mh_ithrha1 小时前
题目:小鱼比可爱(java)
java·开发语言·算法
l1t1 小时前
数独优化求解C库tdoku-lib的使用
c语言·开发语言·python·算法·数独
有一个好名字1 小时前
力扣-奇偶链表
算法·leetcode·链表
wxm6311 小时前
力扣算法题(C++):1、2
java·算法·leetcode
im_AMBER2 小时前
Leetcode 103 反转链表 II
数据结构·c++·笔记·学习·算法·leetcode