(Codeforces Round 855 (Div. 3), problem: (B) Count the Number of Pairs)

80 阅读1分钟

思维

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
	int n, k;
	std::cin >> n >> k;

	int lo[26] {}, up[26] {};
	std::string s;
	std::cin >> s;

	for (auto c : s) {
		std::islower(c) ? lo[c - 'a']++ : up[c - 'A']++;
	}

	int max = 0, ans = 0;
	for (int  i = 0; i < 26; i++) {
		ans += std::min(lo[i], up[i]);
		max += lo[i] + up[i] >> 1;
	}

	ans = std::min(ans + k, max);
	std::cout << ans << "\n";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t;
	std::cin >> t;

	while (t--) {
		solve();
	}
	
	return 0;
}