Waste Separation
Time limit1sMemory limit1024 MB
For each trash string, pick the cheaper option: its recycling bin if it is one recyclable type, otherwise general waste, and sum the minimum costs.
- Level
Easy2 of 10
- Topics
- Implementation, String
- Solved
- No attempts yet
Problem
Jeongwoo has thrown away all of his trash as general waste so far. As a result, his disposal costs were higher than necessary, so he decided to cut costs by separating recyclables. Since he has never sorted waste before, Jiwon agreed to help him.
Jeongwoo has pieces of trash. Each piece is made of several components. The components are plastic , can , vinyl , paper , glass , styrofoam , and general waste .
The sorting rules are as follows.
- Items that can be recycled are plastic , can , vinyl , paper , glass , and styrofoam .
- If a piece of trash consists of only one item , it can be put into the recycling bin for .
- If a piece of trash consists of two or more different items, or it is not a recyclable item, it must be thrown away as general waste.
- Any trash, including recyclables, can be thrown away as general waste.
- The cost of putting trash into the recycling bin for item is .
- The cost of throwing trash away as general waste is .
- The size of a piece of trash equals the length of its string.
For example, suppose there are and , and the cost per unit size is 3 for plastic and 4 for general waste. has size 4 and can go into the plastic recycling bin, so the cost is . contains two or more items, so it cannot go into a recycling bin. It must go to general waste, so the cost is .
Jiwon wants to minimize Jeongwoo's disposal cost. Given pieces of trash, find the minimum total cost to dispose of all of them while following the sorting rules.
Input
The first line contains the number of pieces of trash .
Each of the next lines contains a string describing one piece of trash. Each string has length at most and consists only of the characters .
Line contains the cost per unit size for plastic , can , vinyl , paper , glass , and styrofoam , in that order, separated by spaces.
Line contains the cost per unit size for general waste .
Output
Print the minimum total sorting cost for disposing of all the trash.
Hint
The total cost can exceed , so using a 64-bit integer type is recommended.