This commit is contained in:
2025-12-21 21:18:47 +08:00
parent e0912887c2
commit f14466081c
3 changed files with 52 additions and 0 deletions

20
25/12/comp/21q2.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <string>
#include <unordered_map>
#include <vector>
class Solution {
public:
long long minCost(std::string s, std::vector<int> &cost) {
std::unordered_map<char, long long> m;
int n = cost.size();
long long sum = 0, ans = LLONG_MAX;
for (int i = 0; i < n; i++) {
m[s[i]] += cost[i];
sum += cost[i];
}
for (auto [k, v] : m) {
ans = std::min(ans, sum - v);
}
return ans;
}
};