Skip to content

Latest commit

 

History

History
32 lines (28 loc) · 779 Bytes

24.md

File metadata and controls

32 lines (28 loc) · 779 Bytes
int minCost(string colors, vector<int>& neededTime) {
        
        int n=colors.size();
        int ans=0,flag,i=0;
        while(i<n-1)
        {
            int maxi=neededTime[i];
            flag=0;
            while(colors[i]==colors[i+1])
            {
                ans+=neededTime[i];
                if(maxi<neededTime[i+1])
                    maxi=neededTime[i+1];
                i++;
                flag=1;
            }
            if(flag==1)
            {
                ans+=neededTime[i];
                ans-=maxi;
            }
            else
                i++;
        }

        return ans;
    }