You are playing a game called RuinScape and are currently fighting a tough boss named Araxxi (she is a spider). The fight will last for units of time. Araxxi has types of special attacks that she uses, numbered from to , and she will use a single special attack during each of the units of time. She always uses the same sequence of special attacks, and some special attacks may be repeated in this sequence more than once.
Since you are a skilled player, you know that the key to winning the fight is to counter as many of Araxxi's special attacks as you can. You know the techniques to counter each of the special attacks. Once you activate a technique, all of Araxxi's special attacks that the technique counters will be countered, but you will be hit by all of Araxxi's other special attacks that she uses.
Activating a technique is done on the same unit of time as, but an infinitesimal amount of time before Araxxi's special attack (so if Araxxi uses the attack your technique counters on that unit of time, you will successfully counter it). You can switch techniques during the fight, but after cancelling a technique, there is a delay before you can activate the next technique, meaning you must take unavoidable damage from the special attacks that occur during the delay after you cancel the current technique. Specifically, if the delay has a value , that means you cannot activate another technique until you take damage times. This delay may be different for different techniques. If you play optimally, what is the maximum number of special attacks can you counter?
Input Specification
The first line of input will contain two integers and .
The second line of input will contain integers, the sequence of special attacks Araxxi uses, in order. Each integer will be between and , inclusive.
The third line of input will contain integers, the of which is the delay for the technique to counter Araxxi's attack. Each integer will be between and , inclusive.
Output Specification
The first and only line of output should contain the maximum number of special attacks you can counter.
Constraints
For all subtasks:
Subtask 1 [20%]
Subtask 2 [20%]
Subtask 3 [20%]
All the delays are equal to .
Subtask 4 [40%]
No additional constraints.
Sample Input
5 2
1 2 2 1 2
0 2
Sample Output
4
Explanation of Output for Sample Input
The optimal strategy is to activate the technique to counter type 1 special attacks just before Araxxi uses her first attack, and immediately after, switch to the technique to counter type 2 special attacks and keep using that technique until the end of the fight. You will get hit by one type 1 attack, but you will have managed to counter 4 attacks.
Comments
Kappa.
kc?
Add me
Added.