This commit is contained in:
2025-11-03 22:56:42 +08:00
parent b6c8c03411
commit 9de71de750
3 changed files with 81 additions and 0 deletions

30
25/11/1578.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <string>
#include <vector>
#include <iostream>
int minCost(std::string colors, std::vector<int> &neededTime)
{
int n = colors.size();
colors += '#';
int m = 0, count = 0, ans = 0;
for (int i = 0; i < n; ++i)
{
m = std::max(neededTime[i], m);
count += neededTime[i];
if (colors[i] == colors[i + 1])
{
continue;
};
ans += count - m;
m = 0;
count = 0;
}
return ans;
}
int main()
{
std::string c = "abaac";
std::vector<int> need = {1, 2, 3, 4, 5};
std::cout<<minCost(c, need);
}