Under construction

Still being built. Things may change

Sparkling Stardust

Time limit1sMemory limit512 MB

Summary
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 NN days and check how much stardust she can make.

Star has KK spells that make stardust. Call them spell 1, spell 2, ..., spell KK. The number of stardust made by spell ii is

ΔStardust=⌊base_i(1+combo⋅C100)(1+skill_i⋅s_i100)⌋\Delta Stardust = \lfloor base\_i(1+\frac{combo \cdot C}{100})(1+\frac{skill\_i \cdot s\_i}{100}) \rfloor

  • ΔStardust\Delta Stardust: the number of stardust made.
  • base_ibase\_i: the number of stardust spell ii makes by default.
  • combocombo: the number of consecutive days spells were used. For example, if Star used magic 5 days in a row before today, combo=5combo = 5.
  • skill_iskill\_i: the skill level of spell ii. For example, if Star used spell ii 3 times before today, skill_i=3skill\_i = 3.
  • CC and s_is\_i are constants.

Star's initial fatigue is 0. Each time spell ii is used, fatigue rises by p_ip\_i. 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 RR, 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 NN days.

Input

The first line contains N,K,C,RN,K,C,R separated by spaces. (1≤K≤N≤100 0001 \leq K \leq N \leq 100\,000, 1≤C≤1001 \leq C \leq 100, 1≤R≤1001 \leq R \leq 100)

The second line contains base_1,⋯ ,base_Kbase\_1, \cdots , base\_K separated by spaces. (1≤base_i≤100 0001 \leq base\_i \leq 100\,000)

The third line contains s_1,⋯ ,s_Ks\_1, \cdots , s\_K separated by spaces. (1≤s_i≤1001 \leq s\_i \leq 100)

The fourth line contains p_1,⋯ ,p_Kp\_1, \cdots , p\_K separated by spaces. (1≤p_i≤1001 \leq p\_i \leq 100)

From the fifth line, NN lines follow, each with one spell number l_il\_i (0≤l_i≤K0 \leq l\_i \leq K), the spell Star plans to use on day ii. If l_il\_i is 0, Star rests that day.

All numbers in the input are integers.

Output

Print the total number of stardust made over NN days. If the wand breaks during the plan, print -1.

Examples2

  1. Example 1

    Input
    6 5 26 62
    72 81 47 29 97
    2 75 25 82 84
    17 6 7 2 3
    2
    2
    2
    1
    0
    4
    
    Expected output
    723
    
  2. Example 2

    Input
    7 7 98 25
    12 64 97 23 20 97 80
    17 38 76 83 65 40 41
    15 3 16 6 23 11 34
    2
    7
    0
    7
    7
    6
    6
    
    Expected output
    -1