atcoder#AGC004B. [AGC004B] Colorful Slimes
[AGC004B] Colorful Slimes
Score : points
Problem Statement
Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in colors. Those colors are conveniently numbered through . Snuke currently has no slime. His objective is to have slimes of all the colors together.
Snuke can perform the following two actions:
- Select a color (), such that he does not currently have a slime in color , and catch a slime in color . This action takes him seconds.
- Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color () will become color , and the color of a slime in color will become color . This action takes him seconds.
Find the minimum time that Snuke needs to have slimes in all colors.
Constraints
- are integers.
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Find the minimum time that Snuke needs to have slimes in all colors.
2 10
1 100
12
Snuke can act as follows:
- Catch a slime in color . This takes second.
- Cast the spell. The color of the slime changes: → . This takes seconds.
- Catch a slime in color . This takes second.
3 10
100 1 100
23
Snuke can act as follows:
- Catch a slime in color . This takes second.
- Cast the spell. The color of the slime changes: → . This takes seconds.
- Catch a slime in color . This takes second.
- Cast the soell. The color of each slime changes: → , → . This takes seconds.
- Catch a slime in color . This takes second.
4 10
1 2 3 4
10
Snuke can act as follows:
- Catch a slime in color . This takes second.
- Catch a slime in color . This takes seconds.
- Catch a slime in color . This takes seconds.
- Catch a slime in color . This takes seconds.