Sparkling Stardust
Time limit1sMemory limit512 MB
Given a day-by-day plan of spell casts and rests, compute the total stardust made with combo and skill bonuses, or -1 if fatigue breaks the wand.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Star is practicing a spell that makes stardust. To test her skill, she plans to use magic once a day for days and check how much stardust she can make.
Star has spells that make stardust. Call them spell 1, spell 2, ..., spell . The number of stardust made by spell is
- : the number of stardust made.
- : the number of stardust spell makes by default.
- : the number of consecutive days spells were used. For example, if Star used magic 5 days in a row before today, .
- : the skill level of spell . For example, if Star used spell 3 times before today, .
- and are constants.
Star's initial fatigue is 0. Each time spell is used, fatigue rises by . If fatigue exceeds 100, the wand breaks, no spell can be used afterward, and all stardust made so far is lost. Resting lowers fatigue by , but resets the combo count to 0. Fatigue never drops below 0. If the reduction from resting is larger than the current fatigue, fatigue becomes 0.
Given Star's plan, compute the total number of stardust made over days.
Input
The first line contains separated by spaces. (, , )
The second line contains separated by spaces. ()
The third line contains separated by spaces. ()
The fourth line contains separated by spaces. ()
From the fifth line, lines follow, each with one spell number (), the spell Star plans to use on day . If is 0, Star rests that day.
All numbers in the input are integers.
Output
Print the total number of stardust made over days. If the wand breaks during the plan, print -1.