Gold Stimulation Also Needs a Meal First
Time limit2sMemory limit512 MB
Count the starting levels F_1 where the sums of exactly M ingredients inside the window [F_1, F_1 + D_K] match the plan exactly, shifted by F_1.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String matching, Bit manipulation, Math
- Solved
- No attempts yet
Problem
Bo-seon went to the Namgang Lantern Festival during a trip to Jinju. The festival has many colorful sculptures and fun shows, but Bo-seon, whose motto is 'Even Mount Geumgang needs a meal first,' went looking for the food truck zone with lots of food. Strangely, there was no food truck zone. It turned out the festival had a cooking zone instead.
The cooking zone sells kinds of ingredients. Each ingredient has a stimulation level , and every ingredient is plentiful enough to be used as much as needed. From these ingredients, you choose the kinds of ingredients and how many of each to cook a dish. The stimulation level of a finished dish is the sum of the stimulation levels of the ingredients used. Each cooking session costs a fixed amount of money, and the number of cooking sessions is not limited. However, each dish must use exactly ingredients. Too many ingredients take too long and ruin the taste, and too few make the taste bland.
Bo-seon plans to eat dishes. Bo-seon is a gourmet and cares about the stimulation levels of these dishes. Let be the stimulation level of the -th dish eaten, and let . The meal plan is the increasing sequence , where is always . Any dish whose stimulation level differs from by at least and at most , and which is not in the plan , cannot be made, because similar dishes can be confused.
For example, let the plan be . If is chosen as , then must be and must be . A dish with stimulation level is not in the plan, and its difference from is between and , so it must not be makeable. If a dish with stimulation level can be made, cannot be .
Bo-seon makes every dish that can be made using exactly ingredients. Count the stimulation levels that can serve as while satisfying the conditions above.
Input
The first line contains the number of ingredient kinds , the number of ingredients per dish , and the number of dishes , separated by spaces.
The second line contains , separated by spaces. is the stimulation level of the -th ingredient.
The third line contains , separated by spaces. This is the increasing sequence that describes the meal plan.
All numbers in the input are integers.
Output
Print one line containing the number of stimulation levels that can be under the conditions.
Hint
Python 3 users are recommended to submit with PyPy3.